We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 2d88f45 commit 1f3c1d5Copy full SHA for 1f3c1d5
1 file changed
mod_api/middleware/error_handler.py
@@ -131,3 +131,14 @@ def handle_sqlalchemy_error(error):
131
'An unexpected database error occurred.',
132
http_status=500,
133
)
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