NSLS2 / NSLS2/nsls2api

Register Exception Handlers and Standardize Error Responses

Open
#270 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
0
Forks
13
Avg merge
1h 17m
Merged PRs (30d)
1

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.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading exception_handlers.py and main.py to trace the existing handlers and application setup. Add the error template at templates/error.html, extending _layout.html, and verify the listed HTTP, validation, and unexpected errors produce HTML for web requests and appropriate responses for API requests.

Written by the indexing model from the issue text.

Assessment

Tech stack
fastapi, python
Domain
api, backend
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
72/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.