Handle API Error Responses
Generate robust error handling code for API responses. Create comprehensive error management for REST APIs with retry logic and user feedback.
Prompt Template
Variables to Customize
[PROGRAMMING_LANGUAGE] The programming language to use for the error handling implementation
Example: Python
[API_ENDPOINT] The specific API endpoint being called
Example: https://api.example.com/v1/users
[RESPONSE_FORMAT] Expected API response format
Example: JSON
[AUTH_METHOD] Authentication method used by the API
Example: Bearer Token
[CIRCUIT_BREAKER_NEEDED] Whether to implement circuit breaker pattern
Example: Yes
[MAX_RETRIES] Maximum number of retry attempts
Example: 3
[INITIAL_DELAY] Initial delay before first retry in seconds
Example: 1
[TIMEOUT] Request timeout duration in seconds
Example: 30
[LOGGING_FRAMEWORK] Preferred logging framework or method
Example: Python logging module
Example Output
Pro Tips for Best Results
- Always distinguish between retryable errors (5xx, network issues) and non-retryable errors (4xx client errors)
- Implement exponential backoff with jitter to avoid thundering herd problems when multiple clients retry simultaneously
- Log error details at appropriate levels - DEBUG for retries, ERROR for final failures, CRITICAL for authentication issues
- Consider implementing a circuit breaker pattern for frequently failing APIs to prevent cascade failures
- Parse API error response bodies to extract specific error messages when available, don't just rely on HTTP status codes
Tags
Want 500+ Expert Prompts?
Get the Premium Prompt Pack — organized, tested, and ready to use.
Get it for $29Related Prompts You Might Like
Implement API Pagination System
I need to implement pagination for a REST API endpoint. Please provide a complete implementation with the following requ...
Implement Form Validation with JavaScript
I need help implementing form validation for a web form. Please create a complete solution that includes both HTML struc...
Write Comprehensive Integration Tests
Act as a senior software testing engineer and write comprehensive integration tests for the following system. Your tests...
Generate REST API Endpoints with Documentation
You are an experienced backend developer tasked with creating REST API endpoints for a [APPLICATION_TYPE] application. D...
Generate a Comprehensive Code Review Checklist
Act as a senior software engineer and create a comprehensive code review checklist for [PROGRAMMING_LANGUAGE] projects. ...
Fix Memory Leak in Application
I need help debugging a memory leak in my [PROGRAMMING_LANGUAGE] application. Here are the details: **Application Conte...