Skip to content

BUG-55: a 500 answer is plain text with no CORS header, so the portal sees a network error #216

Closed

Description

@ephico2real2

Part of #20

What is wrong: An exception that no handler takes gives the answer 500 Internal Server Error as plain text. It is not an RFC 9457 problem, and it has no CORS header: Starlette's ServerErrorMiddleware sends it outside each middleware of the application, CORSMiddleware among them. So the portal, on another origin, sees a network error with no status, and a person cannot tell a failure of the service from a failure of the network. Other clients get a body that is not the one shape of each refusal (docs/02, "API contract").

Where: on 418e934: cmapi/src/cmapi/main.py has handlers for Problem, RequestValidationError, TierError and ValueError, and none for Exception. cmapi/src/cmapi/core/observability.py:89-92 counts the 500 and raises it again. The CORS middleware of #206 is added in create_app.

Not measured: the answer of a real browser. The cause is read from Starlette 0.41.3 (starlette/applications.py, build_middleware_stack: ServerErrorMiddleware is the outer one).

How to prove it: a test in cmapi/tests/service makes one route raise RuntimeError, calls it with a listed Origin, and reads the answer with raise_server_exceptions=False. It fails today: the body is not a problem, and Access-Control-Allow-Origin is absent. After the fix the answer is application/problem+json with a registered code, the CORS header and X-Request-Id, the detail has no text of the exception, and the log line has the traceback.

Research mandate: read Starlette's middleware order and FastAPI's guidance for a catch-all handler. Decide where the conversion goes (a middleware inside CORS, not an Exception handler, which runs outside it). The metric of 500 answers must still count each one.

Class

INV. The portal on the API needs a readable answer for each failure.

Activity

  1. added
    bug
    class:INV
    status:open
    sev:low
    Backlog
    on Nov 14, 2026
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

    Backlogbugclass:INVsev:lowstatus:open

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions