From bf038f640fa1bb9e06cbab1a47dcf3af945c0f47 Mon Sep 17 00:00:00 2001 From: Alexander_Kabui Date: Fri, 6 Sep 2024 11:58:15 +0300 Subject: Use application level Exception Handler for Unknown exceptions. --- gn2/wqflask/views.py | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) (limited to 'gn2') diff --git a/gn2/wqflask/views.py b/gn2/wqflask/views.py index 7699c303..336c1182 100644 --- a/gn2/wqflask/views.py +++ b/gn2/wqflask/views.py @@ -264,29 +264,29 @@ def gsearchtable(): @app.route("/gnqna", methods=["POST", "GET"]) @require_oauth2 def gnqna(): + """ Main endpoint to call gn3 gnqna Api endpoint""" + def _error_(resp): + return render_template("gnqa_errors.html", + **{"status_code": resp.status_code, + **resp.json()}) + + def _success_(resp): + return render_template("gnqa_answer.html", + **resp.json()) if request.method == "POST": - try: - def error_page(resp): - return render_template("gnqa_errors.html", - **{"status_code": resp.status_code, **resp.json()}) - - def __success__(resp): - return render_template("gnqa_answer.html", **{"gn_server_url": GN3_LOCAL_URL, **(resp.json())}) - token = session_info()["user"]["token"].either( - lambda err: err, lambda tok: tok["access_token"]) - return monad_requests.put( - urljoin(GN3_LOCAL_URL, - "/api/llm/search"), - json=dict(request.form), - headers={ - "Authorization": f"Bearer {token}" - } - ).then( - lambda resp: resp - ).either( - error_page, __success__) - except Exception as error: - return flask.jsonify({"error": str(error)}), 500 + token = session_info()["user"]["token"].either( + lambda err: err, lambda tok: tok["access_token"]) + return monad_requests.put( + urljoin(GN3_LOCAL_URL, + "/api/llm/search"), + json=dict(request.form), + headers={ + "Authorization": f"Bearer {token}" + } + ).then( + lambda resp: resp + ).either( + _error_, _success_) return render_template("gnqa.html") -- cgit v1.2.3