aboutsummaryrefslogtreecommitdiff
path: root/gn3/errors.py
diff options
context:
space:
mode:
authorAlexander Kabui2024-08-30 16:46:37 +0300
committerGitHub2024-08-30 16:46:37 +0300
commit25345b327f319c49798cef208be950e25f447da6 (patch)
tree56e34bd27b4066dbdc0adcc64bbb9edf8ebd5042 /gn3/errors.py
parentf8c87e6fd1b26887c84a390a1a253d2c629942bc (diff)
parent57b4a4fd5bcb8a2b7f9af856d8f1212c0fbbe0da (diff)
downloadgenenetwork3-25345b327f319c49798cef208be950e25f447da6.tar.gz
Merge pull request #165 from genenetwork/feature/gnqa-search
Feature/gnqa search
Diffstat (limited to 'gn3/errors.py')
-rw-r--r--gn3/errors.py18
1 files changed, 17 insertions, 1 deletions
diff --git a/gn3/errors.py b/gn3/errors.py
index 1833bf6..c53604f 100644
--- a/gn3/errors.py
+++ b/gn3/errors.py
@@ -16,7 +16,7 @@ from authlib.oauth2.rfc6749.errors import OAuth2Error
from flask import Flask, jsonify, Response, current_app
from gn3.auth.authorisation.errors import AuthorisationError
-
+from gn3.llms.errors import LLMError
def add_trace(exc: Exception, jsonmsg: dict) -> dict:
"""Add the traceback to the error handling object."""
@@ -106,6 +106,21 @@ def handle_generic(exc: Exception) -> Response:
return resp
+def handle_llm_error(exc: Exception) -> Response:
+ """ Handle llm erros if not handled anywhere else. """
+ current_app.logger.error(exc)
+ resp = jsonify({
+ "query": exc.args[1],
+ "error_type": type(exc).__name__,
+ "error": (
+ exc.args[0] if bool(exc.args) else "Fahamu gnqa error occurred"
+ ),
+ "trace": traceback.format_exc()
+ })
+ resp.status_code = 500
+ return resp
+
+
def register_error_handlers(app: Flask):
"""Register application-level error handlers."""
app.register_error_handler(NotFound, page_not_found)
@@ -115,6 +130,7 @@ def register_error_handlers(app: Flask):
app.register_error_handler(AuthorisationError, handle_authorisation_error)
app.register_error_handler(RemoteDisconnected, internal_server_error)
app.register_error_handler(URLError, url_server_error)
+ app.register_error_handler(LLMError, handle_llm_error)
for exc in (
EndPointInternalError,
EndPointNotFound,