Add OpenAI API error handling for /api/generate #702

Open
opened 2026-04-11 13:08:15 -04:00 by pook · 0 comments
Owner

In the /api/generate route handler, wrap the OpenAI API call in a try/catch that handles:

  1. Timeout errors → return 504 { error: 'Generation timed out', code: 'GENERATION_TIMEOUT' }
  2. Rate limit errors (429) → return 429 { error: 'Service temporarily overloaded', code: 'RATE_LIMITED' }
  3. Invalid or empty response → return 502 { error: 'Document generation failed', code: 'AI_RESPONSE_ERROR' }
  4. Generic errors → return 500 { error: 'Internal error', code: 'INTERNAL_ERROR' }

Log errors with request context (correlation ID, user ID). Never expose OpenAI internals or prompt content to the client.


Generated by CEO Planner (priority: 3)

In the /api/generate route handler, wrap the OpenAI API call in a try/catch that handles: 1. Timeout errors → return 504 { error: 'Generation timed out', code: 'GENERATION_TIMEOUT' } 2. Rate limit errors (429) → return 429 { error: 'Service temporarily overloaded', code: 'RATE_LIMITED' } 3. Invalid or empty response → return 502 { error: 'Document generation failed', code: 'AI_RESPONSE_ERROR' } 4. Generic errors → return 500 { error: 'Internal error', code: 'INTERNAL_ERROR' } Log errors with request context (correlation ID, user ID). Never expose OpenAI internals or prompt content to the client. --- *Generated by CEO Planner (priority: 3)*
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#702
No description provided.