fix(images): surface real upstream error instead of generic 502#3009
Open
liulinhuai wants to merge 1 commit into
Open
fix(images): surface real upstream error instead of generic 502#3009liulinhuai wants to merge 1 commit into
liulinhuai wants to merge 1 commit into
Conversation
The /v1/images/generations and /v1/images/edits paths routed every non-failover upstream error through the generic handleErrorResponse, whose final switch collapses anything that isn't 401/402/403/429 into a hardcoded 502 "Upstream request failed" — discarding the actual upstream status code, type, code, message, and param. So a gpt-image-2 400 (invalid_request_error, moderation, unsupported parameter, ...) reached the client as an opaque 502. The sibling Chat Completions and Messages compat paths already avoid this via handleCompatErrorResponse, which preserves the real status and message. Add the equivalent for images: handleOpenAIImagesErrorResponse keeps all existing side-effects (ops logging, error-passthrough rules, ShouldHandleErrorCode, account-disable/secondary-failover) but surfaces the real upstream status + type/code/message/param by reusing the existing OpenAIImagesUpstreamError machinery. Both forward paths now call it instead of handleErrorResponse for non-failover errors. Failover behavior (5xx / 401 / 403 / 429 / 529) is unchanged. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
|
All contributors have signed the CLA. ✅ |
Author
|
I have read the CLA Document and I hereby sign the CLA |
Author
|
recheck |
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.
Problem
Requests to
/v1/images/generationsand/v1/images/edits(e.g.gpt-image-2) return an opaque 502 "Upstream request failed" for many upstream errors, hiding the real status code and message. For example, a400 invalid_request_error(unsupported parameter, moderation, invalid size, …) from the upstream reaches the client as a generic 502, making failures undebuggable.Root cause
Both image forward paths routed every non-failover upstream error through the generic
handleErrorResponse, whose finalswitchcollapses anything that isn't 401/402/403/429 into a hardcoded502with the message"Upstream request failed"— discarding the upstream status code, type, code, message, and param.The sibling Chat Completions and Messages compat paths already avoid this via
handleCompatErrorResponse, which preserves the real upstream status and message. The images paths were the only ones still masking.Fix
handleOpenAIImagesErrorResponse, modeled onhandleCompatErrorResponse. It keeps all existing side-effects (ops logging, admin error-passthrough rules,ShouldHandleErrorCode, account-disable / secondary failover) but surfaces the real upstream status code +type/code/message/param, reusing the existingOpenAIImagesUpstreamError+writeOpenAIImagesUpstreamErrorResponsemachinery. ReturningOpenAIImagesUpstreamErroralso lets the images handler treat it as terminal (no fallback double-write).forwardOpenAIImagesOAuthandforwardOpenAIImagesAPIKeynow call it instead ofhandleErrorResponsefor non-failover errors.openAIImagesUpstreamErrorFromHTTPandopenAIImagesErrorTypeForStatus.Failover behavior is unchanged — 5xx / 401 / 403 / 429 / 529 still trigger account failover exactly as before. This only affects errors the gateway had already decided not to retry, which is the class that was being masked.
Tests
Added
TestOpenAIGatewayServiceForwardImages_OAuthUpstreamHTTPErrorSurfacesRealError, asserting an upstream400is passed through with the real status code,type,code,param, and message instead of a generic 502. Fullinternal/serviceandinternal/handlerpackages pass.🤖 Generated with Claude Code