Repository navigation
Description
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 asdetail(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 atINFO, shortened and escaped (escape_log_value()), and Connexion's validation logger is raised toCRITICAL, 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 asdetail(shortened), title as mapped for its class, status fromexc.code, and extension members (e.g.,serviceId=...);ValueErrorfor exceptions without code or description. Andshorten_detail(detail: str) -> str, public, for log messages.- Same as all error responses: the configured
media_type, filtering bypublic_members(ifdetailis 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_detailson 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, andproblem_response()), and the options intemplates/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 asdetail, 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()andshorten_detail()are public and documented. - Tests at 100% coverage (also list reasons, empty reasons,
public_memberswithoutdetail, long details); the strict docs build passes. - No migration note needed (opt-in); the changelog mentions it.
Activity