Generate Error Handling System
- 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
- 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') }
}
- Generate global error handler middleware.
- Add
Result<T, E> type for functions that can fail without throwing.
- 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.