api-error-handling

Implements standardized API error responses with status codes, logging, and circuit breakers.

Updated Jun 22, 2026
One-click install
npx skills add https://github.com/aicodepro/ai-agent-nexi --skill api-error-handling-aicodepro
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: api-error-handling
Source: https://github.com/aicodepro/ai-agent-nexi/tree/main/agent/skills/api-error-handling
Command: npx skills add https://github.com/aicodepro/ai-agent-nexi --skill api-error-handling-aicodepro

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires sentry-sdk, flask, requests, and includes references (resource) components.

What problem does it solve? APIs without consistent error handling return unpredictable responses, leak stack traces to clients, and lack traceability, making debugging and client integration painful. ## Core Features & Use Cases - Standardized Error Responses: Defines a consistent JSON error format with codes, HTTP status, request IDs, and field-level validation details. - Resilience Patterns: Provides circuit breaker and retry-with-exponential-backoff implementations to prevent cascading failures when calling external services. - Framework Implementations: Includes a Node.js/Express global error handler and a Python Flask reference with custom exception classes and Sentry integration. - Use Case: When building a production REST API, use this Skill to add a global error handler that returns structured 4xx/5xx responses with request IDs, plus a circuit breaker around calls to a flaky third-party API. ## Quick Start Ask the AI to add standardized error handling with a global error middleware and circuit breaker to your Express or Flask API.

Frequently Asked Questions about api-error-handling

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I create a global error handler in Express?

Define an error-handling middleware with four parameters (err, req, res, next) registered after all routes. It reads err.status and err.code, builds a standardized JSON error response with the request ID, logs 5xx errors, and sends the response with the appropriate status code.

How to implement a circuit breaker pattern in Python?

Create a CircuitBreaker class tracking failure count and state (CLOSED, OPEN, HALF_OPEN) with a lock for thread safety. After the failure threshold is reached it opens, then transitions to HALF_OPEN after the recovery timeout to test if the service recovered.

What should a standard API error response format include?

A standard error response should include an error code, human-readable message, HTTP status, request ID for traceability, timestamp, and optional field-level details for validation errors. Never expose stack traces to clients.

Does Flask error handling support custom exception classes?

Yes, Flask supports registering error handlers for custom exception classes via @app.errorhandler(ApiError). The handler converts the exception into a JSON response with its code, message, status, and request ID, logging at warning or error level based on severity.

When should I use retry with exponential backoff?

Use retry with exponential backoff for transient failures like network timeouts or rate limits when calling external APIs. Add jitter to the delay to avoid thundering herd, and cap retries so persistent failures surface instead of looping indefinitely.