597c6d48d3
8 blueprints each defined an identical _bad() (two variants: with/without detail). Extracted error_response() into api/_responses.py; each blueprint now imports it `as _bad` so call sites are unchanged. The detail-aware canonical subsumes both variants. Left settings.py's distinct _bad_int and the inline jsonify error sites (not duplicated helpers). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
17 lines
520 B
Python
17 lines
520 B
Python
"""Shared API response helpers."""
|
|
|
|
from quart import jsonify
|
|
|
|
|
|
def error_response(
|
|
error: str, *, status: int = 400, detail: str | None = None, **extra,
|
|
):
|
|
"""JSON error body + HTTP status. `detail` is included only when given;
|
|
`extra` keys are merged into the body. Returns the (response, status)
|
|
tuple Quart expects. Imported as `_bad` by the blueprints."""
|
|
body = {"error": error}
|
|
if detail is not None:
|
|
body["detail"] = detail
|
|
body.update(extra)
|
|
return jsonify(body), status
|