From aj-geddes-useful-ai-prompts-4
Standardizes API error handling with typed error classes, consistent error response formats, retry strategies, circuit breaker patterns, and monitoring integration. Useful for building resilient APIs or debugging production error patterns.
How this skill is triggered — by the user, by Claude, or both
Slash command
/aj-geddes-useful-ai-prompts-4:api-error-handlingThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
- [Overview](#overview)
Build robust error handling systems with standardized error responses, detailed logging, error categorization, and user-friendly error messages. This skill covers the full lifecycle from throwing typed errors through logging, monitoring, and client-facing response formatting.
Minimal standardized error response format:
{
"error": {
"code": "VALIDATION_ERROR",
"message": "Input validation failed",
"statusCode": 422,
"requestId": "req_abc123xyz789",
"timestamp": "2025-01-15T10:30:00Z",
"details": [
{ "field": "email", "message": "Invalid email format", "code": "INVALID_EMAIL" }
]
}
}
Custom error class (Node.js):
class ApiError extends Error {
constructor(code, message, statusCode = null, details = null) {
super(message);
this.code = code;
this.statusCode = statusCode || ERROR_CODES[code]?.status || 500;
this.details = details;
this.timestamp = new Date().toISOString();
}
}
// Usage
throw new ApiError("NOT_FOUND", "User not found", 404);
throw new ApiError("VALIDATION_ERROR", "Missing fields", 422, fieldErrors);
Detailed implementations in the references/ directory:
| Guide | Contents |
|---|---|
| Error Codes & Response Format | Complete ERROR_CODES map, response formatter, global middleware (Node.js + Python) |
| Retry Strategies & Circuit Breaker | Exponential backoff, jitter, circuit breaker pattern |
| Monitoring & Tracking | Sentry integration, error rate metrics, /metrics/errors endpoint |
| Validation Patterns | Input validation, schema guards, detecting bad responses before errors occur |
requestId and traceId in every error for observabilityERROR level; log 4xx at WARN levelnpx claudepluginhub aj-geddes/useful-ai-promptsImplements standardized API error handling with RFC 7807 responses, typed error classes, middleware, and monitoring. Use for consistent HTTP errors across endpoints.
Implements standardized API error responses with status codes, logging, user messages, and circuit breaker for Node.js and Python Flask. Use for production APIs, error recovery, and monitoring integration.
Provides error handling patterns for building resilient applications: retry, circuit breaker, graceful degradation, async error handling, and better debugging experiences.