Claude Skills
CollectionsCompareWorkflowsNominate
Sign inSign up
© 2026 Curated Agent Skills·Learn more about Agent Skills
Back to repository

node-error-handling

verified

Node.js error handling patterns

View on GitHub

Marketplace

alphaagent-team

the-answerai/alphaagent-team

Plugin

aai-stack-node

stack

Repository

the-answerai/alphaagent-team

plugins/aai-stack-node/skills/node-error-handling/SKILL.md

Last Verified

February 1, 2026

Install Skill

Select agents to install to:

Scope:
npx add-skill https://github.com/the-answerai/alphaagent-team/blob/main/plugins/aai-stack-node/skills/node-error-handling/SKILL.md -a claude-code --skill node-error-handling

Installation paths:

Claude
.claude/skills/node-error-handling/
Powered by add-skill CLI

Instructions

# Node.js Error Handling Skill

Patterns for error handling in Node.js applications.

## Error Classes

### Custom Error Classes

```typescript
// Base application error
class AppError extends Error {
  constructor(
    message: string,
    public code: string,
    public statusCode: number = 500,
    public isOperational: boolean = true
  ) {
    super(message)
    this.name = this.constructor.name
    Error.captureStackTrace(this, this.constructor)
  }
}

// Specific error types
class ValidationError extends AppError {
  constructor(message: string, public fields: Record<string, string>) {
    super(message, 'VALIDATION_ERROR', 400)
  }
}

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

class UnauthorizedError extends AppError {
  constructor(message = 'Unauthorized') {
    super(message, 'UNAUTHORIZED', 401)
  }
}

class ForbiddenError extends AppError {
  constructor(message = 'Forbidden') {
    super(message, 'FORBIDDEN', 403)
  }
}

class ConflictError extends AppError {
  constructor(message: string) {
    super(message, 'CONFLICT', 409)
  }
}
```

### Error with Context

```typescript
class ContextualError extends Error {
  public context: Record<string, any>

  constructor(
    message: string,
    context: Record<string, any> = {},
    public cause?: Error
  ) {
    super(message)
    this.name = 'ContextualError'
    this.context = context
  }

  static wrap(error: Error, context: Record<string, any>): ContextualError {
    return new ContextualError(error.message, context, error)
  }
}

// Usage
throw ContextualError.wrap(dbError, {
  operation: 'createUser',
  userId: '123',
})
```

## Async Error Handling

### Express Error Middleware

```typescript
// Async handler wrapper
const asyncHandler = (fn: RequestHandler): RequestHandler => {
  return (req, res, next) => {
    Promise.resolve(fn(req, res, next)).catch(next)
  }
}

// Usage
router.get('/users/:id', asyncHandle

Validation Details

Front Matter
Required Fields
Valid Name Format
Valid Description
Has Sections
Allowed Tools
Instruction Length:
6646 chars