API Error Handling Framework

Design comprehensive API error handling with consistent error formats, codes, and client-friendly messages.

6/11/2026
Prompt
You are a backend architect specializing in API reliability and developer experience.

## CONTEXT
I need to design error handling for my API.

**Requirements:**
- API Framework: {{FRAMEWORK}}
- Error Categories: {{ERROR_CATEGORIES}}
- Logging Requirements: {{LOGGING}}
- Client Types: {{CLIENTS}}

## TASK
Design a comprehensive error handling framework:

### 1. ERROR RESPONSE FORMAT
```json
{
  "error": {
    "code": "VALIDATION_ERROR",
    "message": "Human-readable message",
    "details": [
      {
        "field": "email",
        "issue": "Invalid email format",
        "suggestion": "Use format: user@domain.com"
      }
    ],
    "requestId": "uuid",
    "timestamp": "ISO-8601",
    "documentation": "https://api.docs/errors/VALIDATION_ERROR"
  }
}
```

### 2. ERROR CODE TAXONOMY
| Code | HTTP Status | Category | Description |
|------|-------------|----------|-------------|
| VALIDATION_ERROR | 400 | Client | Invalid input |
| UNAUTHORIZED | 401 | Auth | Missing/invalid token |
| FORBIDDEN | 403 | Auth | Insufficient permissions |
| NOT_FOUND | 404 | Client | Resource not found |
| CONFLICT | 409 | Client | Resource conflict |
| RATE_LIMITED | 429 | Client | Too many requests |
| INTERNAL_ERROR | 500 | Server | Unexpected error |

### 3. ERROR HANDLING MIDDLEWARE
Provide code for centralized error handling.

### 4. VALIDATION ERRORS
Detailed field-level validation messages.

### 5. LOGGING STRATEGY
- What to log
- Log levels
- Sensitive data handling

### 6. CLIENT RETRY GUIDANCE
Include retry-after headers and guidance.

Or press ⌘C to copy

Variables (5)

Replace these placeholders with your own content before using the prompt.

[{FRAMEWORK][{ERROR_CATEGORIES][{LOGGING][{CLIENTS]{ "error": { "code": "VALIDATION_ERROR", "message": "Human-readable message", "details": [ { "field": "email", "issue": "Invalid email format", "suggestion": "Use format: user@domain.com" }

Ready to use?

Copy and paste into your favorite AI tool

Test this prompt live

Try it in our AI Playground with Claude

Open Playground

Explore more Coding prompts

Browse Coding

Command Palette

Search for a command to run...