fix: keep API failures readable when a response is not JSON - #95
Open
nvtoan0201-swe wants to merge 1 commit into
Open
nvtoan0201-swe wants to merge 1 commit into
nvtoan0201-swe wants to merge 1 commit into
Conversation
MuseApi parsed the body as JSON before checking response.ok, so a plain-text 404, an HTML proxy error page, or an empty body surfaced as a SyntaxError parse message instead of the real failure. Route session creation and requests through a shared reader that keeps JSON error messages, falls back to the response status, and reports unreadable success bodies clearly.
nvtoan0201-swe
force-pushed
the
fix/readable-api-errors
branch
from
September 30, 2026 04:49
3e349e1 to
b8313f8
Compare
This branch has not been deployed
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
MuseApi.requestandcreateSessionparsed the body withresponse.json()before checkingresponse.ok. Any failure that is not JSON — Hono's default plain-text 404, a reverse-proxy HTML error page, or an empty body — surfaced in the UI asSyntaxError: Unexpected token ...instead of the real failure.Both paths now use a shared
readApiPayloadreader (apps/mobile/src/api-response.ts) that:errormessage when the server sends one;Request failed (<status>)(or the caller's fallback, e.g. "Could not open your workspace.") when the body is not JSON or carries no message;Regression coverage is in
apps/mobile/test/api-response.test.ts(plain-text failure, HTML failure, JSON failure, caller fallback, empty 204, non-JSON success body).Verification
pnpm test— 210 pass, 0 fail (4 new tests)pnpm lintpnpm typecheck(root + mobile)pnpm --dir apps/worker typecheckThe change is limited to response parsing and was verified with
Responsefixtures. No simulator/device run.Integration limits
No provider, platform export or container path is exercised by this change. Runtime behavior is unchanged except for the error text shown when a response is not JSON.
AI assistance was used to prepare this change; I reviewed the code, tests and checks above.