aboutsummaryrefslogtreecommitdiff
path: root/gn3
diff options
context:
space:
mode:
authorMunyoki Kilyungi2024-02-25 17:37:57 +0300
committerBonfaceKilz2024-02-25 17:57:17 +0300
commit3e1261eab74bada1fd1c037df633a50e9a94eef9 (patch)
treeb9fb55bc998d3b597e63be0ebe04df95ff02dbb0 /gn3
parent1d811a1fa24ff105db458d56ea71a538737082d0 (diff)
downloadgenenetwork3-3e1261eab74bada1fd1c037df633a50e9a94eef9.tar.gz
Correctly handle URLError.
Using the `internal_server_error` function to handle URLError raised an exception because the `pnf` exception did not have some attributes. * gn3/errors.py (url_server_error): New function. (register_error_handlers): Register above function to handle URLError. Signed-off-by: Munyoki Kilyungi <me@bonfacemunyoki.com>
Diffstat (limited to 'gn3')
-rw-r--r--gn3/errors.py10
1 files changed, 9 insertions, 1 deletions
diff --git a/gn3/errors.py b/gn3/errors.py
index 3752a9a..245c791 100644
--- a/gn3/errors.py
+++ b/gn3/errors.py
@@ -42,6 +42,14 @@ def internal_server_error(pnf):
})), 500
+def url_server_error(pnf):
+ """Handler for an exception with a url connection."""
+ return jsonify(add_trace(pnf, {
+ "error": f"URLLib Error no: {pnf.reason.errno}",
+ "error_description": pnf.reason.strerror,
+ }))
+
+
def handle_authorisation_error(exc: AuthorisationError):
"""Handle AuthorisationError if not handled anywhere else."""
current_app.logger.error(exc)
@@ -92,7 +100,7 @@ def register_error_handlers(app: Flask):
app.register_error_handler(OperationalError, handle_sqlite3_errors)
app.register_error_handler(AuthorisationError, handle_authorisation_error)
app.register_error_handler(RemoteDisconnected, internal_server_error)
- app.register_error_handler(URLError, internal_server_error)
+ app.register_error_handler(URLError, url_server_error)
for exc in (
EndPointInternalError,
EndPointNotFound,