fix: surface upstream validation errors#3
Open
aorying wants to merge 1 commit intolidge-jun:mainfrom
Open
Conversation
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.
What changed
This PR keeps upstream image-generation validation errors visible to callers instead of collapsing them into the generic safety-refusal path.
Specifically, when the OAuth proxy receives a non-retryable upstream 4xx response, such as an invalid image size, the server now returns the upstream status, error code, and actionable message back through both generation entry points:
POST /api/generatePOST /api/node/generateWhy
Before this change, an upstream request like
512x512could fail validation, but the app retried it and eventually reported the failure asSAFETY_REFUSAL/Content generation refused after retries.That made the CLI/API response misleading because the user action was not unsafe content; it was a request-parameter validation problem. The original upstream message already explains how to fix the request, so preserving it gives users a clear next step.
Before
ima2 gen "a simple red circle" -s 512x512 -o /tmp/test.pngReturned a generic refusal after retries:
After
The same request returns the original validation error without retrying:
The response also preserves the upstream HTTP status and code, for example:
{ "error": "Invalid size '512x512'. Requested resolution is below the current minimum pixel budget.", "code": "invalid_value" }Implementation notes
message,code,type, andparamon the thrown OAuth error object.Tests
npm testnpm run lint:pkgAdded regression coverage for:
/api/generatereturning invalid-size validation errors instead ofSAFETY_REFUSAL./api/node/generatereturning the same invalid-size validation error shape without retrying.