| Field | Value |
|---|---|
| Status | Proposed |
| Date | 2025-12-12 |
| Updated | 2025-12-12 |
| Authors | Spaarke Engineering |
| Sprint | TBD |
AI-Optimized Versions (load these for efficient context):
- ADR-019 Concise - ~100 lines, decision + constraints + patterns
- API Constraints - MUST/MUST NOT rules for API development
- Error Handling Pattern - ProblemDetails code examples
When to load this full ADR: Error handling strategy, SSE error event structure
Minimal APIs make it easy for each endpoint to invent its own error shape. For AI workloads (including SSE streaming), inconsistent error handling causes:
- Client-side complexity (many special cases)
- Poor debuggability (missing correlation/error codes)
- Security risk (leaking details/content)
The repo already contains a shared helper for consistent ProblemDetails responses:
src/server/api/Sprk.Bff.Api/Infrastructure/Errors/ProblemDetailsHelper.cs
This ADR standardizes how we represent errors across HTTP and SSE.
| Rule | Requirement |
|---|---|
| ProblemDetails for HTTP | All non-streaming HTTP failures return RFC 7807 ProblemDetails (use helpers where available). |
| Stable error codes | ProblemDetails must include a stable errorCode extension where meaningful (especially for AI). |
| Correlation always | Include a correlation identifier (e.g., HttpContext.TraceIdentifier) in error responses and logs. |
| No content leaks | Error details must not include document content, prompts, or model output. |
| SSE terminal error event | SSE endpoints emit a final “error” event with a stable code and correlation ID; do not silently drop connections without a terminal signal when possible. |
| Map upstream failures | Graph/OpenAI/DocIntel failures should map to consistent status codes (429, 503, 500) and stable error codes. |
Applies to:
- BFF endpoints (all API areas)
- AI streaming endpoints (SSE)
- Job status endpoints (ADR-017)
- Standardizing every single error title string
- Use
.ProducesProblem(...)in endpoint metadata. - Prefer
ProblemDetailsHelperhelpers for common cases (e.g.,AiUnavailable,AiRateLimited,Forbidden).
SSE endpoints should:
- Stream content events as usual.
- On error, emit a final event that includes:
type: "error"done: trueerrorCode(stable)message(safe)correlationId
- Client can’t distinguish rate limit vs outage → retry storms.
- Missing correlation → slow incident response.
- Leaking details → security/privacy incident.
When adding a new endpoint:
- Decide the ProblemDetails shape first.
- Define a stable
errorCodeset for the feature. - Ensure logs and ProblemDetails share correlation.
- Non-streaming endpoints return ProblemDetails on failure.
- Errors include correlation ID.
- AI-related errors include stable
errorCode. - SSE endpoints emit a terminal error event (when possible).
- No prompts/document contents are included in errors/logs.
| Date | Version | Changes | Author |
|---|---|---|---|
| 2025-12-12 | 0.1 | Initial proposed ADR | Spaarke Engineering |