API error handling system with typed errors and client SDK
Views
9.6K
Copies
1.8K
Likes
1.8K
Comments
0
Copy rate
19.0%
Prompt
Design and implement a comprehensive error handling system for a [framework] REST API that includes:
1. A typed error hierarchy (base error class + specific errors)
2. Global exception filter that formats errors consistently
3. Error codes enum for client consumption
4. Request ID tracking for debugging
5. Error logging with context (user, route, stack trace)
6. Client-friendly error responses (no internal details leaked)
7. Validation error formatting (field-level errors)
8. A TypeScript client helper for [client_framework] that parses these errors
The error response format should be:
```json
{ "error": { "code": "RESOURCE_NOT_FOUND", "message": "...", "requestId": "...", "details": [] } }
```Customise this prompt
Fill in 2 variables to personalise this prompt
Preview
Design and implement a comprehensive error handling system for a [framework] REST API that includes:
1. A typed error hierarchy (base error class + specific errors)
2. Global exception filter that formats errors consistently
3. Error codes enum for client consumption
4. Request ID tracking for debugging
5. Error logging with context (user, route, stack trace)
6. Client-friendly error responses (no internal details leaked)
7. Validation error formatting (field-level errors)
8. A TypeScript client helper for [client_framework] that parses these errors
The error response format should be:
```json
{ "error": { "code": "RESOURCE_NOT_FOUND", "message": "...", "requestId": "...", "details": [] } }
```
Example output