plugins/aai-stack-node/skills/node-error-handling/SKILL.md
February 1, 2026
Select agents to install to:
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-handlingInstallation paths:
.claude/skills/node-error-handling/# 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