feat(backend): 重构 HTTP 错误处理为 RFC7807 标准并优化多个 service
This commit is contained in:
@@ -20,6 +20,16 @@ This file governs `backend/**` only. Keep it minimal, enforceable, and non-dupli
|
||||
- Use project logging (`core.logging`), never `print()` in runtime code.
|
||||
- HTTP errors must follow RFC 7807 (`application/problem+json`).
|
||||
|
||||
## HTTP Error Contract (Must)
|
||||
|
||||
- Backend must construct error payload using RFC7807 fields plus stable extension fields: `code` and optional `params`.
|
||||
- `code` must be machine-readable `UPPER_SNAKE_CASE`; do not use free-text `detail` as the only contract.
|
||||
- Error code registry source of truth: `docs/protocols/common/http-error-codes.md`.
|
||||
- Any create/modify/deprecate of error codes must update `docs/protocols/common/http-error-codes.md` in the same change.
|
||||
- Keep response media type as `application/problem+json`.
|
||||
- Long-term layering target: HTTP transport details stay in routers/global handlers; service/repository/dependencies should raise domain errors (`ApiProblemError` or domain-specific exceptions), not `HTTPException`.
|
||||
- When refactoring existing code, prefer replacing `HTTPException` in service/repository/dependencies with `ApiProblemError` while preserving status/code semantics.
|
||||
|
||||
## Configuration & Secrets
|
||||
|
||||
- Read env only through `core.config.settings` (`Settings` / `config`).
|
||||
|
||||
Reference in New Issue
Block a user