Now liveThe Skillselion MCP - thousands of ranked skills, loaded into your agent mid-task. No install.Get it →
secondsky avatar

Api Error Handling

  • 330 installs
  • 202 repo stars
  • Updated August 4, 2026
  • secondsky/claude-skills

api-error-handling is a Claude Code skill from secondsky/claude-skills that guides consistent REST API error responses, status codes, and failure payloads for developers building backend HTTP services.

About

api-error-handling is an agent skill in the secondsky/claude-skills collection focused on structuring HTTP API error handling for backend services. Based on its slug and catalog placement, it helps developers define consistent error response shapes, map exceptions to status codes, and communicate validation and server failures clearly to API consumers. Teams reach for it when new endpoints lack a unified error contract or when agents generate handlers with ad-hoc JSON error bodies. Documentation in the repository is minimal, so treat it as a focused backend pattern skill rather than a full framework integration.

  • api-error-handling

Api Error Handling by the numbers

  • 330 all-time installs (skills.sh)
  • +10 installs in the week ending Jul 27, 2026 (Skillselion tracking)
  • Ranked #1,229 of 4,347 Backend & APIs skills by installs in the Skillselion catalog
  • Data as of Aug 5, 2026 (Skillselion catalog sync)
npx skills add https://github.com/secondsky/claude-skills --skill api-error-handling

Add your badge

Show developers this skill is listed on Skillselion. Paste this into your README.

Listed on Skillselion
Installs330
repo stars202
Last updatedAugust 4, 2026
Repositorysecondsky/claude-skills

How do you structure consistent REST API error responses?

Use api-error-handling for development tasks

Who is it for?

Backend developers standardizing error contracts across REST API endpoints in a new or inconsistent service.

Skip if: Frontend-only teams handling UI toast messages without designing server-side error payload contracts.

When should I use this skill?

User asks to implement API error handling, standardize HTTP error responses, or map exceptions to REST status codes.

What you get

Error response schema, HTTP status code mapping rules, validation error format, and exception-to-response handler patterns.

  • Error response schema
  • Status code mapping guide
  • Validation error format

Files

SKILL.mdMarkdownGitHub ↗

API Error Handling

Implement robust error handling with standardized responses and proper logging.

Standard Error Response Format

{
  "error": {
    "code": "VALIDATION_ERROR",
    "message": "Invalid request parameters",
    "status": 400,
    "requestId": "req_abc123",
    "timestamp": "2025-01-15T10:30:00Z",
    "details": [
      { "field": "email", "message": "Invalid email format" }
    ]
  }
}

Error Class (Node.js)

class ApiError extends Error {
  constructor(code, message, status = 500, details = null) {
    super(message);
    this.code = code;
    this.status = status;
    this.details = details;
  }

  static badRequest(message, details) {
    return new ApiError('BAD_REQUEST', message, 400, details);
  }

  static notFound(resource) {
    return new ApiError('NOT_FOUND', `${resource} not found`, 404);
  }

  static unauthorized() {
    return new ApiError('UNAUTHORIZED', 'Authentication required', 401);
  }
}

// Global error handler
app.use((err, req, res, next) => {
  const status = err.status || 500;
  const response = {
    error: {
      code: err.code || 'INTERNAL_ERROR',
      message: status === 500 ? 'Internal server error' : err.message,
      status,
      requestId: req.id
    }
  };

  if (err.details) response.error.details = err.details;
  if (status >= 500) logger.error(err);

  res.status(status).json(response);
});

Circuit Breaker Pattern

class CircuitBreaker {
  constructor(threshold = 5, timeout = 30000) {
    this.failures = 0;
    this.threshold = threshold;
    this.timeout = timeout;
    this.state = 'CLOSED';
  }

  async call(fn) {
    if (this.state === 'OPEN') throw new Error('Circuit open');
    try {
      const result = await fn();
      this.failures = 0;
      return result;
    } catch (err) {
      this.failures++;
      if (this.failures >= this.threshold) {
        this.state = 'OPEN';
        setTimeout(() => this.state = 'HALF_OPEN', this.timeout);
      }
      throw err;
    }
  }
}

Additional Implementations

See references/python-flask.md for:

  • Python Flask error handling with custom exceptions
  • Circuit breaker with automatic recovery
  • Retry with exponential backoff
  • Sentry integration

Best Practices

  • Use consistent error format across all endpoints
  • Include request IDs for traceability
  • Log errors at appropriate severity levels
  • Never expose stack traces to clients
  • Distinguish client errors (4xx) from server errors (5xx)
  • Provide actionable error messages

Related skills

FAQ

What does api-error-handling help implement?

api-error-handling helps implement consistent REST API error responses—status codes, JSON error bodies, and validation failure formats—so backend HTTP services communicate failures predictably to API clients.

When should I invoke api-error-handling?

Invoke api-error-handling when building or refactoring backend endpoints that need a unified error contract instead of inconsistent ad-hoc error JSON across routes.

Backend & APIsbackendintegrations

This week in AI coding

Five minutes, every Monday - the tools, releases and tactics for developers.

unsubscribe anytime.