🔌

API Error Response Standard

Define a consistent error response format across all API endpoints

prompt template
Design a standardized error response format for this API:

**API style:** [STYLE — e.g., "REST", "GraphQL", "tRPC"]
**Consumers:** [CONSUMERS — e.g., "React frontend, mobile app, third-party developers"]

Generate:
1. **Error envelope** — consistent JSON structure for all error responses
2. **Error codes** — application-specific error codes with descriptions
3. **HTTP status mapping** — which errors map to 400, 401, 403, 404, 409, 422, 429, 500
4. **Validation errors** — field-level error details for form validation
5. **Error factory** — utility functions to create errors consistently
6. **Client-side handling** — TypeScript types and error parsing utilities
7. **Localization** — support for error messages in multiple languages
8. **Documentation** — error code reference table for API docs

Include the error classes, middleware, and client-side utilities.

How to Use This Prompt

  1. 1Copy the prompt template above
  2. 2Paste into Claude, ChatGPT, or Cursor
  3. 3Replace [bracketed placeholders] with your specific project details
  4. 4Iterate on the AI output to refine and customize the results