fix: handle empty/error bodies in TokenTester token exchange#142
Merged
antosubash merged 1 commit intomainfrom Apr 30, 2026
Merged
fix: handle empty/error bodies in TokenTester token exchange#142antosubash merged 1 commit intomainfrom
antosubash merged 1 commit intomainfrom
Conversation
Reading res.json() directly threw 'Unexpected end of JSON input' when the /connect/token response body was empty, and the !res.ok branch discarded the OpenIddict error JSON. Read the body as text once, parse it defensively, and surface error/error_description in the alert.
Deploying simplemodule-website with
|
| Latest commit: |
9e89fef
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://f10719a3.simplemodule-website.pages.dev |
| Branch Preview URL: | https://claude-fix-token-exchange-js.simplemodule-website.pages.dev |
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 the cryptic error
Token exchange failed: Failed to execute 'json' on 'Response': Unexpected end of JSON inputshown by the dashboardTokenTesterafter an OAuth callback.Root cause
In
modules/Dashboard/src/SimpleModule.Dashboard/Pages/components/TokenTester.tsx, the/connect/tokenresponse was parsed viaawait res.json()unconditionally. Two failure modes:res.json()itself throwsUnexpected end of JSON input, which becomes the user-visible error.{ error, error_description }) — the!res.okbranch threw${res.status} ${res.statusText}and discarded the body, hiding the actual reason for the failure (e.g.invalid_grant, PKCE mismatch, etc.).Change
JSON.parseonly if non-empty.!res.ok, surfaceerror_description/errorfrom the parsed body when available.access_tokenis present before using it.Accept: application/jsonto be explicit about the expected response type.Test plan
stateorcode_verifier) and confirm the alert now shows the OpenIddicterror_descriptioninstead of the generic JSON-parse error.Generated by Claude Code