Skip to content

Commit 2d88f45

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

1 file changed

Lines changed: 12 additions & 25 deletions

File tree

mod_api/middleware/error_handler.py

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -51,37 +51,24 @@ def handle_403(error):
5151
)
5252

5353

54-
def _is_api_request():
55-
return request.path.startswith('/api/')
56-
57-
58-
@mod_api.app_errorhandler(404)
54+
@mod_api.errorhandler(404)
5955
def handle_404(error):
6056
"""Not found."""
61-
if _is_api_request():
62-
return make_error_response(
63-
'not_found',
64-
getattr(error, 'description', 'Resource not found.'),
65-
http_status=404,
66-
)
67-
from run import not_found
68-
return not_found(error)
57+
return make_error_response(
58+
'not_found',
59+
getattr(error, 'description', 'Resource not found.'),
60+
http_status=404,
61+
)
6962

7063

71-
@mod_api.app_errorhandler(405)
64+
@mod_api.errorhandler(405)
7265
def handle_405(error):
7366
"""Handle method-not-allowed errors for API routes."""
74-
if _is_api_request():
75-
resp = make_error_response(
76-
'method_not_allowed',
77-
'Method not allowed.',
78-
http_status=405,
79-
)
80-
if hasattr(error, 'valid_methods') and error.valid_methods:
81-
resp.headers['Allow'] = ', '.join(error.valid_methods)
82-
return resp
83-
84-
resp = make_response("Method not allowed", 405)
67+
resp = make_error_response(
68+
'method_not_allowed',
69+
'Method not allowed.',
70+
http_status=405,
71+
)
8572
if hasattr(error, 'valid_methods') and error.valid_methods:
8673
resp.headers['Allow'] = ', '.join(error.valid_methods)
8774
return resp

0 commit comments

Comments
 (0)