Skip to content
Back to skills

Api Error Handler

ASecurity

Add consistent error handling to API routes. Creates standardized error responses, logging, and error classes. Triggers on "add error handling", "error handling", "standardize errors".

  • 7 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added November 24, 2026
developmentgobashnodeexpressdebuggingapi

Works with

  • api

Security analysis

A100/100

Scanned November 24, 2026

npx -y skills add luqiang-code/claude-code-skills --skill api-error-handler --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Api Error Handler?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Api Error Handler
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/luqiang-code-api-error-handler/badge)](https://www.skillsdirectory.com/skills/luqiang-code-api-error-handler)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: api-error-handler
description: |
  Add consistent error handling to API routes. Creates standardized error responses,
  logging, and error classes. Triggers on "add error handling", "error handling",
  "standardize errors".
metadata:
  type: tool
  version: "1.0.0"
  author: community
  tags: [api, error-handling, express, fastify]
triggers:
  - "add error handling"
  - "standardize errors"
  - "error handler"
  - "consistent error responses"
allowed-tools:
  - Read
  - Write
  - Edit
  - Bash
---

# API Error Handler

Add consistent, production-grade error handling to API routes.

## When to Use
- API routes lack standardized error responses
- Error handling is inconsistent across endpoints
- User mentions "error handling", "error responses", "error middleware"

## When NOT to Use
- GraphQL APIs (different error format)
- WebSocket endpoints (different patterns)
- The project already has a mature error handling layer

## Workflow
1. Scan API routes to understand current error handling patterns
2. Identify the framework (Express, Fastify, Koa, etc.)
3. Create an `AppError` class with: statusCode, code, message, details
4. Create error middleware that catches all errors and returns JSON:
   ```json
   { "error": { "code": "VALIDATION_ERROR", "message": "...", "details": [...] } }
   ```
5. Add error categories: ValidationError, AuthError, NotFoundError, RateLimitError
6. Wire into existing routes — replace bare `throw new Error()` with `AppError` subclasses
7. Add request ID to error responses for traceability
8. Run existing tests to verify nothing breaks

## Output Structure
```
src/
├── errors/
│   ├── AppError.ts           # Base error class
│   ├── ValidationError.ts    # 400
│   ├── AuthError.ts          # 401
│   ├── ForbiddenError.ts     # 403
│   ├── NotFoundError.ts      # 404
│   └── RateLimitError.ts     # 429
├── middleware/
│   └── errorHandler.ts       # Error middleware
```

## Key Principles
- Never leak stack traces in production
- Always include a machine-readable `code` field
- Log errors with request ID for debugging
- DON'T catch errors you can't handle — let the middleware do it
- Use HTTP status codes semantically

## Notes
- Don't wrap every route in try-catch — use the error middleware
- Production errors should NOT include internal details
- Add `NODE_ENV` check: include stack traces only in development

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in development →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.