secondsky avatar

Api Error Handling

A solid foundation for production API error handling with standardized JSON responses, proper status codes, and request tracing. Includes a custom error class with static helpers for common scenarios, a global Express middleware handler, and a circuit breaker implementation for dealing with flaky downstream services. The code is opinionated in the right ways: shields users from stack traces, separates client from server errors, and includes request IDs for debugging. If you're tired of inconsistent error formats across your endpoints or need to add resilience patterns without reinventing the wheel, this gives you the scaffolding. Python Flask examples are included in the references.

skills.sh installs
455
GitHub stars
248
last updated
Aug 21, 2026

Install

$ npx -y skills add secondsky/claude-skills --skill api-error-handling --agent claude-code

Installs into .claude/skills of the current project.

Files

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);
  }
}

Sponsors

Details

Repository
github.com/secondsky/claude-skills
Categories
Backend & APIs, DevOps & CI/CD, Debugging
First seen
Jun 3, 2026

More from secondsky/claude-skills

All 146
1sickn33 avatarapi-testing-observability-api-mocksickn33/antigravity-awesome-skillsapi testing observability api mock451skills.sh installs
2secondsky avatarwebsocket-implementationsecondsky/claude-skillsImplements real-time WebSocket communication with connection management, room-based messaging, and horizontal scaling. Use when building chat systems, live noti440skills.sh installs
3secondsky avatarapi-filtering-sortingsecondsky/claude-skillsBuilds flexible API filtering and sorting systems with query parameter parsing, validation, and security. Use when implementing search endpoints, building data 432skills.sh installs
4onewave-ai avatardatabase-schema-designeronewave-ai/claude-skillsDesign optimized database schemas for SQL and NoSQL databases including tables, relationships, indexes, and constraints. Creates ERD diagrams, migration scripts426skills.sh installs
5vercel avatarai-gatewayvercel/vercel-pluginai gateway423skills.sh installs
6sickn33 avatarcc-skill-backend-patternssickn33/antigravity-awesome-skillscc skill backend patterns421skills.sh installs