diff --git a/app/__init__.py b/app/__init__.py index c9e346d..384fb20 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -181,6 +181,15 @@ def setup_error_handlers(app: Flask) -> None: mimetype="application/json", ) + @app.errorhandler(405) + def method_not_allowed(error: HTTPException) -> Response: + """Handle 405 Method Not Allowed errors.""" + return Response( + json.dumps({"error": "Method not allowed"}), + status=405, + mimetype="application/json", + ) + @app.errorhandler(500) def internal_error(error: HTTPException) -> Response: """Handle 500 Internal Server errors.""" @@ -199,6 +208,9 @@ def setup_error_handlers(app: Flask) -> None: @app.errorhandler(Exception) def handle_exception(error: Exception) -> Response: """Handle unhandled exceptions with generic 500 response.""" + # Re-raise HTTP exceptions to their proper handlers + if isinstance(error, HTTPException): + return error # type: ignore[return-value] app.logger.exception( "Unhandled exception: %s [rid=%s]", str(error), getattr(g, "request_id", "-") )