Add OpenAI API error handling with retry to /api/generate endpoints #442

Open
opened 2026-04-10 15:56:36 -04:00 by pook · 0 comments
Owner

All /api/generate endpoints call the OpenAI API. When OpenAI fails (timeout, 429, 500), users get raw errors. Add the same error handling pattern:

  1. Wrap OpenAI calls in try/catch with specific error handling
  2. 429 → 503 with Retry-After header
  3. Timeout (>30s) → 504 with retry message
  4. 500 → 502 with generic user message, detailed server-side log
  5. Single retry with 1s backoff for transient 500s
  6. Structured JSON error responses: { error: string, code: string }

Acceptance: All /api/generate endpoints return graceful errors for OpenAI failures. No unhandled rejections. Test with a mock that returns each error code.


Generated by CEO Planner (priority: 2)

All /api/generate endpoints call the OpenAI API. When OpenAI fails (timeout, 429, 500), users get raw errors. Add the same error handling pattern: 1. Wrap OpenAI calls in try/catch with specific error handling 2. 429 → 503 with Retry-After header 3. Timeout (>30s) → 504 with retry message 4. 500 → 502 with generic user message, detailed server-side log 5. Single retry with 1s backoff for transient 500s 6. Structured JSON error responses: { error: string, code: string } Acceptance: All /api/generate endpoints return graceful errors for OpenAI failures. No unhandled rejections. Test with a mock that returns each error code. --- *Generated by CEO Planner (priority: 2)*
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
pook/compliancebot#442
No description provided.