Skip to content

feat(errors): serve validation error details #461

Closed

Description

@uniqueg

FOCA's error handler serves the problem details (RFC 9457) mapped to the exception class, so a request rejected by Connexion's validation (BadRequestProblem, ExtraParameterProblem) gets the same fixed detail whatever was wrong with it, and clients can't tell which field failed. Meanwhile, Connexion logs the validator's message at ERROR (logger connexion.decorators.validation), in full and unescaped, although validators quote rejected values, which can be as large as the request body. Apps also can't return request-specific details (e.g., which identifier conflicts) without building responses themselves. elixir-cloud-aai/cloud-registry, the template for FOCA apps, does this in cloud_registry/exceptions.py: validation_problem() (registered for both Connexion exceptions in cloud_registry/app.py, which also silences Connexion's logger), problem(exc, **extensions), shorten_detail() and MAX_DETAIL_LENGTH = 500 (tests in tests/test_exceptions.py).

Move this into FOCA's error handling (foca.errors.exceptions, ExceptionConfig):

  • exceptions.validation_details: bool = False (new): if true, responses to Connexion's validation exceptions get the validator's reason as detail (a list, e.g., for form data, joined with "; "), falling back to the mapped details if there is none; title and status as mapped. The reason is logged at INFO, shortened and escaped (escape_log_value()), and Connexion's validation logger is raised to CRITICAL, so that the full message isn't logged.
  • exceptions.max_detail_length: int = 500 (new, ≥ 1): longer details are shortened in the middle (keeping start and end, e.g., the field names at the end), joined by …, in responses and log messages.
  • problem_response(exc: HTTPException, **extensions: Any) -> Response (new, public): a response with the request-specific description of a werkzeug exception as detail (shortened), title as mapped for its class, status from exc.code, and extension members (e.g., serviceId=...); ValueError for exceptions without code or description. And shorten_detail(detail: str) -> str, public, for log messages.
  • Same as all error responses: the configured media_type, filtering by public_members (if detail is not public, it isn't sent), and the headers of the exception (_build_headers(), e.g., WWW-Authenticate).
  • Backwards compatible: off by default, so responses and logs stay as they are. Open question for the maintainer: turn validation_details on by default (and always silence Connexion's unescaped log message, in line with FOCA's log policy), e.g., from FOCA 1.0?
  • Docs: docs/configuration/exceptions.md (both options, with an example response, and problem_response()), and the options in templates/config.yaml.

Follow-up in cloud-registry (separate issue there): set exceptions.validation_details: true, use problem_response() and shorten_detail() from FOCA, and delete validation_problem(), problem(), _response(), shorten_detail(), MAX_DETAIL_LENGTH, the handler registrations and the logger setting in create_app().

Acceptance criteria

  • With validation_details: true, validation errors get the validator's reason as detail, shortened, with the configured media type and public members; with the default, responses are unchanged.
  • Connexion's validation message is not logged in full when the option is on; the shortened reason is logged escaped.
  • problem_response() and shorten_detail() are public and documented.
  • Tests at 100% coverage (also list reasons, empty reasons, public_members without detail, long details); the strict docs build passes.
  • No migration note needed (opt-in); the changelog mentions it.

Activity

  1. added this to the v0.18.0 milestone on Oct 24, 2026
  2. added
    priority: medium
    status: triage
    type: feature
    workload: hours
    status: in progress
    and removed
    status: triage
    on Oct 24, 2026
  3. removed
    status: in progress
    on Oct 24, 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: mediumtype: featureworkload: hours

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions