fix: fall back to entire response body when 'error' field is missing#1746
Open
Limitless2023 wants to merge 1 commit intoopenai:masterfrom
Open
fix: fall back to entire response body when 'error' field is missing#1746Limitless2023 wants to merge 1 commit intoopenai:masterfrom
Limitless2023 wants to merge 1 commit intoopenai:masterfrom
Conversation
When an OpenAI-compatible API returns error information in fields other than 'error' (e.g. 'detail' or 'message'), the client now falls back to using the entire response body instead of reporting '(no body)'. This aligns behavior with the Python client, which already falls back to the full response body when the 'error' field is absent. Fixes openai#1734
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 error information in fields other than
error(e.g.detailormessage), the Node client currently reports422 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:errorfield) — still works as beforedetailfield — now shows the error contentmessagefield — now shows the error content(no body)Before / After
Before: An error response like
{"detail": "422: The model gpt-5-gibberish does not exist."}would produce:After: The same response now produces:
This matches the Python client's behavior of falling back to the full response body when the
errorfield is absent.