Skip to content

Register Exception Handlers and Standardize Error Responses #270

Description

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions