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

ParameterTypeRequiredDescription
typestringYesError handling type: api, form, global
loggingbooleanNoInclude error logging (default: true)
trackingstringNoError tracking service: sentry, datadog
customErrorsarrayNoCustom 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 TypeStatus CodeWhen to Use
ValidationError400Invalid input data
UnauthorizedError401Missing or invalid auth
ForbiddenError403Insufficient permissions
NotFoundError404Resource not found
ConflictError409Duplicate or conflict
RateLimitError429Too many requests
AppError500General 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...