Skip to content

Commit 1f3c1d5

Browse files
committed
Fixed a silent error handler error
1 parent 2d88f45 commit 1f3c1d5

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

mod_api/middleware/error_handler.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,3 +131,14 @@ def handle_sqlalchemy_error(error):
131131
'An unexpected database error occurred.',
132132
http_status=500,
133133
)
134+
135+
136+
@mod_api.after_app_request
137+
def convert_api_errors_to_json(response):
138+
"""Catch routing errors that were handled by global app handlers and convert them to JSON."""
139+
if request.path.startswith(_API_PREFIX):
140+
if response.status_code == 404:
141+
return make_error_response('not_found', 'Resource not found.', http_status=404)
142+
if response.status_code == 405:
143+
return make_error_response('method_not_allowed', 'Method not allowed.', http_status=405)
144+
return response

0 commit comments

Comments
 (0)