Skip to content

[FEAT] Register Custom Exception Handlers in FastAPI App #295

@lil-aditya

Description

@lil-aditya

Description

The project defines a structured custom error handling system using AppError and register_exception_handlers, but the handlers are never registered with the FastAPI application.

As a result, when AppError is raised (for example, when a template is not found), FastAPI falls back to its default exception handling and returns a 500 Internal Server Error instead of the intended status code.

This hides meaningful error responses from API consumers and reduces API reliability.


Rationale

Custom exception handling logic already exists in the codebase but is not wired into the FastAPI app.

Without registering these handlers:

  • AppError(status_code=404) incorrectly returns 500
  • API consumers receive misleading responses
  • The structured error handling system becomes ineffective

Registering the handlers restores the intended API behavior.


Proposed Solution

Register the custom exception handlers in the FastAPI application entrypoint.

API Entrypoint

File: main.py

from fastapi import FastAPI
from api.routes import templates, forms
+from api.errors.handlers import register_exception_handlers

app = FastAPI()
+register_exception_handlers(app)

app.include_router(templates.router)
app.include_router(forms.router)

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