Skip to content

[BUG]: AppError handler is never registered #311

@ishansurdi

Description

@ishansurdi

name: 🐛 Bug Report
about: Create a report to help us improve FireForm.
title: "[BUG]: AppError handler is never registered"
labels: bug
assignees: ''


⚡️ Describe the Bug

The app defines a custom error handler for AppError exceptions in api/errors/handlers.py, but it is never registered in the FastAPI application.

When any route raises an AppError, the app does not use the handler. Instead, the exception propagates as an unhandled error and returns a plain-text 500 Internal Server Error.

This breaks the intended error contract and prevents proper HTTP status codes and JSON error responses from reaching clients.

👣 Steps to Reproduce

  1. Start the API
  2. Send a POST request to /forms/fill with a template_id that does not exist
  3. Example: POST /forms/fill with body {"template_id": 999999, "input_text": "test"}
  4. Observe the response

📉 Expected Behavior

The route should catch the AppError and return:

  • HTTP status: 404 (as specified in the error)
  • Content-Type: application/json
  • Body: {"error": "Template not found"}

🖥️ Environment Information

  • OS: Windows
  • Docker/Compose Version: N/A
  • Ollama Model used: N/A

📸 Screenshots/Logs

Actual response received:

HTTP/1.1 500 Internal Server Error
Content-Type: text/plain; charset=utf-8

Internal Server Error

Test failure output:

FAILED test_main_branch_bugs.py::TestBug1_AppErrorHandlerNotRegistered
E   api.errors.base.AppError: Template not found

Scope verification: A temporary test route that only raises AppError also returns 500, proving this is app-wide, not route-specific.

🕵️ Possible Fix

The handler needs to be registered during app initialization in api/main.py.

Currently, handlers.register_exception_handlers() exists but is never called. The fix is to import the handlers module and call the registration function after creating the FastAPI app instance, before including any routers.

💬 Discussion

Not 100% sure if this is the intended behavior or if I'm missing something. If others are hitting this too, I can raise a PR with a fix. Open to any inputs or corrections on this!

Can anyone confirm if they've seen this issue or have thoughts on the best approach?

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