Skip to content

refactor(errors): make errors framework-neutral #633

Closed

Description

@uniqueg

Apps raise Werkzeug exceptions (werkzeug.exceptions.NotFound, ...) and key their exception maps by Werkzeug and Connexion 2 classes. In cloud-registry, proTES and trs-filer this happens in exceptions.py. FOCA's handler (foca/errors/exceptions.py) builds Flask Responses and reads Connexion 2's validation logger and problem classes (#461).

The ASGI release runs on Connexion 3 AsyncApp, without Flask:

  • error handlers have the signature (ConnexionRequest, Exception) -> ConnexionResponse;
  • connexion.exceptions.Forbidden and Unauthorized are no longer Werkzeug classes;
  • ExtraParameterProblem becomes a subclass of BadRequestProblem.

A scratch test with Connexion 3.3.0 showed that a handler registered for Werkzeug's HTTPException catches subclasses and keeps their headers (e.g., Allow). So the change can be prepared now, and apps can stop importing Werkzeug and Connexion exceptions.

Do:

  • foca.errors exception classes for the statuses apps use:
    • BadRequest, Unauthorized, Forbidden, NotFound, MethodNotAllowed, Conflict, PayloadTooLarge, UnprocessableContent, InternalServerError, ServiceUnavailable, plus a base class HTTPError;
    • each with code, description and optional headers.
    • In 0.22 they subclass their Werkzeug counterparts, so existing handlers and except werkzeug... keep working. In the ASGI release they get their own base class, with the same names and attributes.
  • Stable names for Connexion's problems that apps map: RequestValidationProblem (BadRequestProblem), ExtraParameterProblem, AuthenticationProblem (OAuthProblem), AccessDeniedProblem (Connexion's Forbidden). They are aliases of the Connexion 2 classes now and of the Connexion 3 classes in the ASGI release, so apps' exception maps don't change.
  • FOCA's own code raises foca.errors classes: ownership*.py, access_control_server.py, service_info.py, connexion_app.py, auth.py (the RFC 6750 challenge goes in headers).
  • Problem core without Flask: build_problem(), header building and validation details (feat(errors): serve validation error details #461) work on plain data (exception, status, headers, problem dict). A thin Connexion 2 adapter turns the result into a Flask response. The ASGI release only adds an ASGI adapter.
  • Validation details no longer depend on the logger name connexion.decorators.validation in the core. That logger name stays in the Connexion 2 adapter only.

Acceptance criteria

  • foca.errors exports the classes and aliases above; documented (API reference, docs/configuration/exceptions.md), with an example exception map using only foca.errors names.
  • foca/ raises no Werkzeug or Connexion exception directly; the problem core has no flask import.
  • Responses don't change: existing error tests pass unchanged, including headers (fix(errors): keep headers of HTTP exceptions #343) and validation details (feat(errors): serve validation error details #461).
  • Tests show that a foca.errors class and its Werkzeug base map to the same problem.

Decided

  • Class names follow RFC 9110 (PayloadTooLarge, UnprocessableContent, ...), as proposed.
  • Mapping raw Werkzeug exceptions keeps working in 0.22 but logs a deprecation warning (once per exception class); it stops at the first release candidate of the ASGI release. Document this in docs/configuration/exceptions.md and the migration guide.
  • Werkzeug stays installed (Connexion 3 depends on it); apps just must not import it.

Prepares #188.

Activity

  1. added this to the v0.22.0 milestone on Nov 3, 2026
  2. added
    priority: high
    status: triage
    type: maintenance
    workload: days
    on Nov 3, 2026
  3. removed
    status: triage
    on Nov 9, 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

    priority: hightype: maintenanceworkload: days

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions