Resolve API Error Responses
This loop standardizes API error responses across the application to improve client-side error handling and debugging. It ensures all error responses follow a consistent structure (e.g., RFC 7807 Problem Details format) with appropriate HTTP status codes and machine-readable error codes.
Goal
Standardize API error responses
How to Run
Run this loop in your coding agent to standardize API error responses. The agent will analyze current errors, implement a unified response format, apply it across all endpoints, and validate through automated tests.
- 01
Start the Loop Agent
Paste the kickoff prompt into your preferred coding agent (Cursor, Claude Code, etc.) to begin the standardization process.
- 02
Execute Check Command
After each iteration, run 'npm run test:api-errors' to validate error response consistency and structure.
- 03
Iterate Until Exit Condition
The agent will self-pace through analysis, implementation, and testing until all error validation tests pass or maximum iterations are reached.
Workflow Steps
- 01
Step 1
Review all existing error handling code to identify inconsistencies in structure, status codes, and error messages.
- 02
Step 2
Implement a centralized error handler or middleware that formats all API errors according to the chosen standard (e.g., RFC 7807).
- 03
Step 3
Update all route handlers and catch blocks to use the new standardized error response format.
- 04
Step 4
Execute 'npm run test:api-errors' to verify that all error responses meet the required format and contain necessary information.
- 05
Step 5
Ensure the standardized approach handles all error scenarios including validation failures, authentication issues, and server errors.
Kickoff Prompt
Start the "Resolve API Error Responses" loop. Goal: Standardize API error responses Max iterations: 10 Between iterations run: npm run test:api-errors Exit when: Error validation tests pass Analyze the current API error handling in this codebase. Create a standardized error response format following RFC 7807 Problem Details specification. Apply this format consistently across all API endpoints and error scenarios. Run 'npm run test:api-errors' to validate your implementation. Continue iterating until all error validation tests pass. Self-pace this loop. After each iteration, run `npm run test:api-errors` and evaluate the output, and only continue if the exit condition is not met (Error validation tests pass). Stop when the exit condition passes or 10 iterations are reached. Give a short status update each pass.
Guardrails
hardcoded- ·Do not modify existing error handling that is already compliant with the target standard
- ·Ensure backward compatibility where possible by maintaining existing error message content
- ·Use existing validation libraries or middleware instead of reinventing solutions
- ·Verify that standardized errors are logged consistently for observability
- ·Avoid introducing new dependencies unless absolutely necessary for error formatting
Flow Diagram
Related loops — API
API
Fix Failing Integration Endpoints
Automatically detects and resolves issues in failing API integration endpoints through iterative testing and code modifications.
API
API Performance Budget
A coding loop focused on optimizing API performance to ensure P95 latency stays under a defined target threshold. This loop iteratively runs load tests, analyzes bottlenecks, and implements optimizations until the goal is achieved or maximum iterations are reached.
API
Generate Missing API Docs
Automatically identifies and documents all undocumented API endpoints in the project. The agent iteratively generates OpenAPI/Swagger documentation until all endpoints meet the required documentation standards.