Skip to main content
skill CX Codex

api-error-handling · aj-geddes — Claude Code skill: what it does, how to install

This skill structures API error handling around shared responses, validation, logs, retries, and monitoring. Use it while debugging failures or adding recovery paths.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add aj-geddes/useful-ai-prompts --skill api-error-handling -a claude-code
Open on GitHub

What api-error-handling does

api-error-handling gives an API a shared error model across endpoints. It covers typed errors, HTTP status handling, request and trace IDs, client-facing messages, logging, and error-rate tracking. Input checks happen before the main request work.

Its references/ directory contains guides for the ERROR_CODES map and response formatting in Node.js and Python, exponential backoff, circuit breakers, Sentry integration, error metrics, the /metrics/errors endpoint, and validation guards. A Node.js ApiError class is included.

The guidance rules out retries for non-idempotent operations and 4xx responses. It also separates log levels for server and client errors, while sensitive data such as tokens and passwords must stay out of logs.

What it helps with

  • standardize error responses across API endpoints
  • attach requestId and trace data to failures
  • add exponential-backoff retries for transient errors
  • validate request data before processing
  • track error spikes with metrics and alerts

Example prompts for the agent

  • Apply one error response shape to every endpoint and add requestId.
  • Set up exponential backoff and a circuit breaker for transient API failures.
  • Review this Node.js API’s input validation and error middleware.

How to install api-error-handling

1Skills CLI (Vercel)

npx skills add aj-geddes/useful-ai-prompts --skill api-error-handling -a claude-code

2Manually: put the files in place

~/.claude/skills/api-error-handling/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/api-error-handling/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about api-error-handling

How do I install api-error-handling in Claude Code?

Run npx skills add aj-geddes/useful-ai-prompts --skill api-error-handling -a claude-code, then use ~/.claude/skills/api-error-handling/SKILL.md.

What does api-error-handling do?

It guides shared API error responses, typed errors, validation, logging, monitoring, retries, and circuit-breaker recovery patterns.

What is included in api-error-handling?

The references/ directory covers error codes and response formatting, retry strategies, Sentry and metrics, plus validation examples. Some implementation guides target Node.js and Python.

Source text

SKILL.md · MIT
---
name: api-error-handling
description: >
  Implement comprehensive API error handling with standardized error responses,
  logging, monitoring, retry logic, and validation patterns. Use when building
  resilient APIs, debugging issues, improving error reporting, implementing
  retry logic, handling HTTP error codes, managing API timeouts, designing
  error response handling, or adding circuit breaker patterns.
---

# API Error Handling

## Table of Contents

- [Overview](#overview)
- [When to Use](#when-to-use)
- [Quick Start](#quick-start)
- [Reference Guides](#reference-guides)
- [Best Practices](#best-practices)

## Overview

Build robust error handling systems with standardized error responses, detailed
logging, error categorization, and user-friendly error messages. This skill
covers the full lifecycle from throwing typed errors through logging, monitoring,
and client-facing response formatting.

## When to Use

- Handling API errors consistently across endpoints
- Debugging production issues with request tracing
- Implementing error recovery strategies (retry, circuit breaker)
- Monitoring and alerting on error rates
- Providing meaningful, actionable error messages to clients
- Validating request inputs before processing
- Tracking error patterns over time

## Quick Start

Minimal standardized error response format:

```json
{
  "error": {
    "code": "VALIDATION_ERROR",
    "message": "Input validation failed",
    "statusCode": 422,
    "requestId": "req_abc123xyz789",
    "timestamp": "2025-01-15T10:30:00Z",
    "details": [
      { "field": "email", "message": "Invalid email format", "code": "INVALID_EMAIL" }
    ]
  }
}
```

Custom error class (Node.js):

```javascript
class ApiError extends Error {
  constructor(code, message, statusCode = null, details = null) {
    super(message);
    this.code = code;
    this.statusCode = statusCode || ERROR_CODES[code]?.status || 500;
    this.details = details;
    this.timestamp = new Date().toISOString();
  }
}

// Usage
throw new ApiError("NOT_FOUND", "User not found", 404);
throw new ApiError("VALIDATION_ERROR", "Missing fields", 422, fieldErrors);
```

## Reference Guides

Detailed implementations in the `references/` directory:

| Guide | Contents |
|---|---|
| [Error Codes & Response Format](references/error-codes-reference.md) | Complete `ERROR_CODES` map, response formatter, global middleware (Node.js + Python) |
| [Retry Strategies & Circuit Breaker](references/retry-strategies.md) | Exponential backoff, jitter, circuit breaker pattern |
| [Monitoring & Tracking](references/monitoring-patterns.md) | Sentry integration, error rate metrics, `/metrics/errors` endpoint |
| [Validation Patterns](references/validation-examples.md) | Input validation, schema guards, detecting bad responses before errors occur |

## Best Practices

### ✅ DO

- Use a consistent error response format across all endpoints
- Include `requestId` and `traceId` in every error for observability
- Log 5xx errors at `ERROR` level; log 4xx at `WARN` level
- Provide actionable error messages — tell the client what to fix
- Use standard HTTP status codes (4xx client errors, 5xx server errors)
- Implement retry with exponential backoff for transient failures
- Use circuit breakers to prevent cascade failures
- Validate inputs early and return all field errors at once
- Monitor error rates and alert on anomalous spikes

### ❌ DON'T

- Expose stack traces or internal implementation details to clients
- Return HTTP 200 for error responses
- Silently swallow errors
- Log sensitive data (passwords, tokens, PII)
- Use vague messages like "Something went wrong"
- Mix error handling logic with business logic
- Retry non-idempotent operations or client errors (4xx)
- Return different error shapes from different endpoints

© aj-geddes · MIT · aj-geddes/useful-ai-prompts

Similar skills

All skills for Backend and APIs →

api-error-handling by other authors comes first.

From the same set149

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor