fix(error): fall back to full response body when error field is absent#1784
Open
s-zx wants to merge 1 commit intoopenai:masterfrom
Open
fix(error): fall back to full response body when error field is absent#1784s-zx wants to merge 1 commit intoopenai:masterfrom
error field is absent#1784s-zx wants to merge 1 commit intoopenai:masterfrom
Conversation
When an OpenAI-compatible API returns an error response that does not include an `error` field (e.g. using `detail` or other custom fields), the Node.js client previously produced unhelpful messages like "422 status code (no body)". This fix mirrors the Python client behavior: if `body.error` is not present, the entire response body is used as the error detail. The existing `makeMessage` logic already handles this case by calling JSON.stringify on non-string error values, so downstream error messages will now include the full response body when no `error` field is found.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #1734
When an OpenAI-compatible API returns an error response that does not include an
errorfield (e.g. usingdetail,message, or other custom fields at the top level), the Node.js client produced unhelpful error messages like422 status code (no body).This is because
APIError.generate()extracted onlybody.errorand passedundefinedto the error constructors when that field was missing — themakeMessagelogic then had nothing to display.Change
In
src/core/error.ts, update the error extraction inAPIError.generate()to fall back to the full response body whenbody.erroris not present:This mirrors the behavior of the Python client, which falls back to including the entire response body in the error message when no
errorfield is found. The existingmakeMessagelogic already handles this correctly by callingJSON.stringify()on non-string error values.Example
With a response body like
{"detail": "422: The model gpt-5-gibberish does not exist."}:422 status code (no body)422 {"detail":"422: The model gpt-5-gibberish does not exist."}