openai-node
openai-node copied to clipboard
fix: fall back to entire response body when 'error' field is missing
Summary
Fixes #1734
When an OpenAI-compatible API returns error information in fields other than error (e.g. detail or message), the Node client currently reports 422 status code (no body) instead of showing the actual error content. This differs from the Python client, which falls back to the entire response body.
Changes
src/core/error.ts: InAPIError.generate(), whenerrorResponse.errorisundefined, fall back toerrorResponseitself (the entire parsed JSON body) instead of passingundefinedto the error constructor. This is a one-line change:?? errorResponse.tests/error.test.ts: Added tests covering:- Standard OpenAI error response (with
errorfield) — still works as before - Non-standard response with
detailfield — now shows the error content - Non-standard response with
messagefield — now shows the error content - Truly empty response — still shows
(no body) - Raw text fallback — still works as before
- Standard OpenAI error response (with
Before / After
Before: An error response like {"detail": "422: The model gpt-5-gibberish does not exist."} would produce:
UnprocessableEntityError: 422 status code (no body)
After: The same response now produces:
UnprocessableEntityError: 422 {"detail": "422: The model gpt-5-gibberish does not exist."}
This matches the Python client's behavior of falling back to the full response body when the error field is absent.