api-error-handler

A tool for adding consistent error handling to API routes, which are the parts of a web service that receive requests and return responses. It defines shared error types, JSON error responses, logging, and request identifiers.

In plain words
What is it for?
Use it to standardise validation, authentication, missing-resource, and rate-limit errors across supported API routes, then run the existing tests.
Why use it?
It replaces inconsistent errors and unclear failure responses with a common format that clients and developers can handle more reliably. It is intended for HTTP API routes, not GraphQL or WebSocket endpoints.

Skill for Claude CodeCodex

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/luqiang-code/claude-code-skills/api-error-handler
Any agent
npx skills add luqiang-code/claude-code-skills --skill api-error-handler
Clone the repo
git clone --depth 1 https://github.com/luqiang-code/claude-code-skills

Made for: Claude Code, Codex.

Per session 40 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 588 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00040 $0.00588
Opus 5 $0.00020 $0.00294
Sonnet 5 $0.00008 $0.00118
Haiku 4.5 $0.00004 $0.00059

Measured yesterday against content hash 3972c82c5234, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

api-error-handler scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured yesterday.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

community-skills/api-error-handler/SKILL.md · 76 lines

What it actually says

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:
    { "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
Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. yesterday First seen · 76 lines · 40 tokens per session scan A 3972c82c5234

Subscribe to this mod's changes

api-error-handler is a skill published in the GitHub repository luqiang-code/claude-code-skills (2 stars, last pushed 3mo ago), licensed MIT. It adds 40 tokens to every session and 588 once invoked, about $0.0002 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.