Error handler

From berkcangumusisik/claude-code-practices · View interactive version

Error handler is an AI agent skill from the GitHub repository berkcangumusisik/claude-code-practices. Creates a centralized error handling system with typed errors and proper HTTP responses

How to use this skill

Skill file

Generate Error Handling System

  1. Check existing error handling:
grep -rn "catch\|try\|throw\|Error(" src/ --include="*.ts" -l | head -10
grep -rn "class.*Error" src/ --include="*.ts" | head -10
  1. Generate typed error classes:
export class AppError extends Error {
  constructor(
    message: string,
    public readonly statusCode: number,
    public readonly code: string,
    public readonly isOperational = true,
  ) {
    super(message)
    this.name = this.constructor.name
  }
}

export class NotFoundError extends AppError {
  constructor(resource: string) {
    super(`${resource} not found`, 404, 'NOT_FOUND')
  }
}

export class ValidationError extends AppError {
  constructor(details: ZodIssue[]) {
    super('Validation failed', 400, 'VALIDATION_ERROR')
  }
}

export class UnauthorizedError extends AppError {
  constructor() { super('Unauthorized', 401, 'UNAUTHORIZED') }
}
  1. Generate global error handler middleware.
  1. Add Result<T, E> type for functions that can fail without throwing.
  1. Replace generic try/catch blocks with typed errors throughout the codebase.
Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.