aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander_Kabui2024-09-06 11:58:15 +0300
committerAlexander_Kabui2024-09-06 11:58:15 +0300
commitbf038f640fa1bb9e06cbab1a47dcf3af945c0f47 (patch)
tree51be8889bbdcf09bb3412c773b45cf164816ebae
parenta221d82a16428012a577924279af262a9c9f67a4 (diff)
downloadgenenetwork2-bf038f640fa1bb9e06cbab1a47dcf3af945c0f47.tar.gz
Use application level Exception Handler for Unknown exceptions.
-rw-r--r--gn2/wqflask/views.py44
1 files changed, 22 insertions, 22 deletions
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")