fix(core): return a code instead of an empty response for an empty failure body - #134
Merged
Conversation
…ilure body The auth-flow routes forward the API's failure body rather than interpreting it, and an empty body left nothing to forward: the caller got a bare 4xx with no content, and the React SDK fell back to a generic message with no way to tell an expired session from a rate limit from an upstream outage. The proxy routes already had a fallback, so the two families disagreed on the one case where the caller had least to go on. readPassthroughFailure forwards a body when there is one and returns upstream_error when there is not. A present body is still untouched, including the top-level code the SDK reads for OAuth failures. Closes #125
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.
Closes #125.
Problem
The auth-flow routes forward the auth API's failure body rather than interpreting it. An empty body left nothing to forward, so the caller got a bare 4xx with no content:
POST /loginGET /oauth/providersPATCH /admin/users/:id{"error":"admin_request_failed"}The proxy routes already had a fallback via
readUpstreamFailure, so the two families disagreed on precisely the case where the caller has least to go on. Downstream,toSeamlessAuthErrorinseamless-auth-reactreads the body for a message, finds none, and uses the per-call fallback string, so the user sees a generic failure whether the session expired, the request was rate limited, or the API was down.Fix
readPassthroughFailure(data, fallback?)forwards the body when there is one and returns a code when there is not. The auth-flow handlers now route through it.Verified end to end against a running adapter:
Only the first line changes. A present body is still forwarded untouched, including the top-level
codethe React SDK reads to tell OAuth failures apart, which is the constraint that shaped theerrorBodycontract in the first place.Note the rate-limit row: a non-JSON body is not empty here, because
authFetchalready turns plain text into{ message: text }. Only a genuinely empty body hits the fallback.New exports
readPassthroughFailureandUPSTREAM_ERROR_CODE, both from@seamless-auth/core.Tests
packages/core/tests/passthroughFailure.test.js: four body shapes forwarded untouched, four empty-ish values falling back, a caller-supplied fallback, and the invariant that a result never carries both anerrorBodyand anerrorCode.failureWireFormatguard, so the wire shape is locked alongside the others.Checks
pnpm buildclean.pnpm testpasses: 372 tests across the three packages.