Skip to content

feat: simplify exceptions handling API #240

Closed

Description

@uniqueg

The ExceptionConfig() model/API is unnecessarily complicated.

Simplify with a focus on usability.

Activity

  1. added
    priority: low
    type flag: spec change
    workload: hours
    on May 20, 2024
  2. added this to the v1.0.0 milestone on May 20, 2024
  3. moved this to Todo other in FOCA releaseon May 20, 2024
  4. kushagra189 commented on Jun 15, 2024

    @kushagra189
    Contributor

    Any suggestions here?

  5. uniqueg commented on Jun 17, 2024

    @uniqueg
    MemberAuthor

    Yes, I'm already working on it (I will describe it in the PR once it's done, but will take some weeks). Upgrading to Connexion 3 will require this change anyway.

  6. self-assigned this
    on Jun 17, 2024
  7. uniqueg commented on Oct 18, 2026

    @uniqueg
    MemberAuthor

    Refined proposal

    Status update: the bug fixes (503, MRO lookup, single log record) are in PR 6. For v0.14.0 we would simplify the API itself and make the handler independent of Flask, so that the Connexion 3 migration only needs to swap a thin adapter:

    • Core: a pure build_problem(exc, conf: ExceptionConfig) -> tuple[dict, int] that resolves the problem along type(exc).__mro__, then falls back to the exception's HTTP status (code or status_code attribute), then to 500. This means werkzeug, Connexion and (later) Starlette exceptions with the same status share one entry.
    • Adapter: register_exception_handler(app, conf) binds the config by closure instead of reading current_app; today it returns a Flask Response, later a ConnexionResponse.
    • Defaults: RFC 9457 problem details keyed by status code (title, status, optional detail); no need to list werkzeug classes.
    • Config: replace required_members, extension_members, status_member, public_members and private_members with:
      • mapping: optional dotted path to a dict {exception class: {status, title, detail?, ...}} (replaces exceptions; status is always the status member);
      • public_members: optional flat list of top-level members to return (default: all);
      • logging: unchanged (oneline/minimal/regular/none), with _log_exception taking the enum directly.
    • Fixes the shallow merge of nested public_members by not supporting nested filters anymore.

    Acceptance criteria

    • build_problem unit-tested without any app: MRO resolution, status-code fallback, default 500, member filtering.
    • Handler never touches current_app; HTTP tests for a werkzeug 404, a Connexion 401, a custom mapped exception and an unmapped Exception (body and application/problem+json).
    • ExceptionConfig, template, README and migration notes updated; old keys removed.

    Breaking changes
    Configs must drop required_members, extension_members, status_member, private_members and nested public_members, and rename exceptions to mapping. proTES and cloud-registry exceptions.py dicts keep working if each entry has status and title; entries that only differ from the defaults can be deleted.

    Planned PR
    7 (feat(errors)!: simplify exceptions API).

  8. moved this from Todo other to Done in FOCA releaseon Oct 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

priority: lowtype flag: spec changeworkload: hours

Type

No type

Projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions