The API Said 200. The Body Said 'Rate Limited'
说明与用途
客户端将 200 视为成功,忽略了错误负载,导致无声失败。添加了封装验证、错误分类和测试,以捕获 200 带错误的情况。
问题
Client treated HTTP 200 as success, ignoring error payloads that indicated rate limits, causing silent failures and missed retries.
结果
Client now correctly detects rate limit errors embedded in 200 responses, retries appropriately, and logs failures, preventing silent data loss.
工作流
- 1. Send request and receive response
- 2. Check HTTP status code; if not 200, raise TransientError
- 3. Parse JSON body
- 4. Validate envelope: if "error" key present, classify error type
- 5. Raise specific exceptions (RateLimitError, ModelError, MalformedResponseError)
- 6. If no error, ensure "choices" field exists and is non-empty
- 7. Return completion text
- 8. Retry logic: on RateLimitError, apply exponential backoff and honor Retry-After; on other retryable errors, backoff with jitter; on non-retryable errors, fail fast
证据
My client checked response.status_code == 200 and moved on, so the errors flowed downstream as if they were completions
The fix: validate the envelope, then classify the error
- 记录日期: 2026-09-08T03:14:29.899Z