diff options
author | Alexander Kabui | 2024-09-06 11:17:18 +0300 |
---|---|---|
committer | GitHub | 2024-09-06 11:17:18 +0300 |
commit | cfeb54b776e95194381d26cff02ea738ad4fd3e0 (patch) | |
tree | 1a7cf011bbeb61df90963d79237643bc9f8611f5 /gn3/errors.py | |
parent | 8e28770342b65cff78441670f1841e0130dc9c4b (diff) | |
parent | 8cb85c8f8c12180702cfc3a257bf9a513ac4da3d (diff) | |
download | genenetwork3-cfeb54b776e95194381d26cff02ea738ad4fd3e0.tar.gz |
Merge pull request #188 from genenetwork/chores/merge-gnqa-api
Chores/merge gnqa api
Diffstat (limited to 'gn3/errors.py')
-rw-r--r-- | gn3/errors.py | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/gn3/errors.py b/gn3/errors.py index f618bab..ec7a554 100644 --- a/gn3/errors.py +++ b/gn3/errors.py @@ -17,7 +17,7 @@ from flask import Flask, jsonify, Response, current_app from gn3.oauth2 import errors as oautherrors 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.""" @@ -118,6 +118,21 @@ def handle_local_authorisation_errors(exc: oautherrors.AuthorisationError): })), 400 +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) @@ -127,6 +142,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, |