error-handling Skill
Implement consistent error management with custom error classes, handlers, and logging.
Overview#
The error-handling skill generates robust error handling infrastructure for your application, including custom error classes, response formatters, and logging utilities.
Usage#
Use the error-handling skill to create a comprehensive error handling system for my API.
Parameters#
| Parameter | Type | Required | Description |
|---|---|---|---|
type | string | Yes | Error handling type: api, form, global |
logging | boolean | No | Include error logging (default: true) |
tracking | string | No | Error tracking service: sentry, datadog |
customErrors | array | No | Custom error types to generate |
Generated Output#
Custom Error Classes#
Loading code block...
Error Response Format#
Loading code block...
Error Handler Wrapper#
Loading code block...
Route Handler with Error Handling#
Loading code block...
Error Logging#
Loading code block...
Client-Side Error Handling#
Loading code block...
Server Action Error Handling#
Loading code block...
Features Included#
- Custom error classes with status codes
- Consistent error response format
- Error handler wrapper for API routes
- Zod validation error formatting
- Error logging with context
- Client-side error handling
- Server Action error patterns
Customization Options#
Use the error-handling skill with:
- type: "api"
- logging: true
- tracking: "sentry"
- customErrors: ["PaymentError", "QuotaExceededError"]
Best Practices#
Error Classification#
| Error Type | Status Code | When to Use |
|---|---|---|
| ValidationError | 400 | Invalid input data |
| UnauthorizedError | 401 | Missing or invalid auth |
| ForbiddenError | 403 | Insufficient permissions |
| NotFoundError | 404 | Resource not found |
| ConflictError | 409 | Duplicate or conflict |
| RateLimitError | 429 | Too many requests |
| AppError | 500 | General server error |
Operational vs System Errors#
- Operational errors: Expected errors (validation, not found, unauthorized)
- System errors: Unexpected errors (bugs, infrastructure failures)
Log operational errors at warn level, system errors at error level.
Never Expose Internal Details#
Loading code block...
Related Skills#
- api-endpoint - API route patterns
- validation - Input validation
- auth-flow - Authentication errors