返回统一结构化 API 错误响应。
(error, status: int = None, context: dict = None)
| 55 | |
| 56 | |
| 57 | def api_error_response(error, status: int = None, context: dict = None): |
| 58 | """返回统一结构化 API 错误响应。""" |
| 59 | app_error = ensure_app_error(error, context=context) |
| 60 | if status is not None: |
| 61 | app_error.status = status |
| 62 | status_code = app_error.status |
| 63 | return jsonify(error_payload(app_error)), status_code |
| 64 | |
| 65 | |
| 66 | def validation_error(detail: str, suggestion: str = "请检查输入后重试") -> AppError: |