Skip to content

fix(errors): keep headers of HTTP exceptions #343

Closed

Description

@uniqueg

Why?

FOCA's problem handler (_problem_handler_json in foca/errors/exceptions.py) builds error responses from the problem details, status and media type only. Headers that Werkzeug's HTTP exceptions carry are dropped, although standards require them:

  • 405 Method Not Allowed: Allow (RFC 9110 §15.5.6).
  • 401 Unauthorized: WWW-Authenticate (RFC 9110 §11.6.1; for bearer tokens RFC 6750 §3, e.g. Bearer error="invalid_token"), which clients use to tell "token expired, log in again" from other errors.
  • 429 / 503: Retry-After, if set.

Found in the cloud-registry v0.3.0 pre-release review (e.g. POST /service-info returns 405 without Allow).

How?

  1. Copy the headers from HTTPException.get_headers() into the problem response, except Content-Type (FOCA sets the problem media type).
  2. Have FOCA's own token validation raise 401s with WWW-Authenticate: Bearer (with error="invalid_token" and a short error_description where the token was present but invalid, RFC 6750 §3.1), and realm if configured.
  3. Tests for 405 (Allow), 401 (WWW-Authenticate), 503 with retry_after (Retry-After), and that Content-Type stays the problem media type.
  4. Release notes entry; this goes into a patch release (0.15.1) so cloud-registry v0.3.0 can use it.

Acceptance criteria

  • Error responses keep the headers of the exception (except Content-Type); tests cover 405, 401 and 503.
  • 401s from FOCA's auth carry WWW-Authenticate: Bearer ….
  • Documented in the release notes.

Activity

  1. added
    priority: high
    status: in progress
    type: bug
    workload: hours
    on Oct 21, 2026
  2. added a commit that references this issue on Oct 21, 2026
  3. uniqueg commented on Oct 21, 2026

    @uniqueg
    MemberAuthor

    Done in #349.

  4. removed
    status: in progress
    on Oct 21, 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: bugworkload: hours

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions