Add unified RequestValidationError handler to unify error response schema
- Add RequestValidationError handler that converts Pydantic validation errors to unified ErrorResponse format - Ensures all error responses return consistent schema: code, detail, metadata, correlation_id - Add field_errors count and first_field location to metadata for validation errors - Register handler in exception handler hierarchy before HTTPException handler - Add comprehensive tests for validation error responses - Update Backend-Development.md documentation to include correlation_id field and validation error details - All 44 error-related tests pass (38 existing + 6 new validation tests) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -1,45 +1,3 @@
|
||||
## [IMPORTANT] API pagination doesn't return metadata
|
||||
|
||||
**Where found**
|
||||
|
||||
- `backend/app/routers/history.py` — returns bare list, no pagination metadata
|
||||
- All paginated routers have same issue
|
||||
|
||||
**Why this is needed**
|
||||
|
||||
Frontend receives bare list, cannot determine: total results, whether more pages exist, last page number. Must guess or re-query.
|
||||
|
||||
**Goal**
|
||||
|
||||
Return pagination metadata with every paginated response.
|
||||
|
||||
**What to do**
|
||||
|
||||
1. Create response wrapper:
|
||||
```python
|
||||
class PaginatedResponse(BaseModel):
|
||||
data: list[Item]
|
||||
pagination: PaginationMetadata
|
||||
```
|
||||
|
||||
2. Update all paginated routers to return this wrapper
|
||||
3. Update frontend to use metadata for UI
|
||||
|
||||
**Possible traps and issues**
|
||||
|
||||
- `SELECT COUNT(*)` is slow on large tables
|
||||
- Response shape change — old frontend may not handle
|
||||
|
||||
**Docs changes needed**
|
||||
|
||||
- Update API documentation § Pagination
|
||||
|
||||
**Doc references**
|
||||
|
||||
- `backend/app/utils/pagination.py`
|
||||
|
||||
---
|
||||
|
||||
## [IMPORTANT] Error response schema inconsistent
|
||||
|
||||
**Where found**
|
||||
|
||||
Reference in New Issue
Block a user