Problem
Exception handlers are defined in exception_handlers.py but are not imported in main.py, so they are not being registered with the application.
Error handling also needs to be standardized:
- Web requests should render an HTML error page instead of returning JSON.
- Errors should use a consistent
HTTPException format.
Proposed Changes
-
Register the exception handlers in main.py.
-
Handle:
StarletteHTTPException - HTTP errors (400, 401, 403, 404, etc.)
RequestValidationError - validation errors (422)
Exception - unexpected errors (500)
-
Use a consistent HTTPException structure with the appropriate status code and error message.
-
Render error.html for web requests.
-
Add templates/error.html extending _layout.html.
Expected Behavior
- Errors are handled consistently across the application.
- Web errors render a consistent HTML error page.
- API errors return the appropriate HTTP error response.
Problem
Exception handlers are defined in
exception_handlers.pybut are not imported inmain.py, so they are not being registered with the application.Error handling also needs to be standardized:
HTTPExceptionformat.Proposed Changes
Register the exception handlers in
main.py.Handle:
StarletteHTTPException- HTTP errors (400, 401, 403, 404, etc.)RequestValidationError- validation errors (422)Exception- unexpected errors (500)Use a consistent
HTTPExceptionstructure with the appropriate status code and error message.Render
error.htmlfor web requests.Add
templates/error.htmlextending_layout.html.Expected Behavior