Skip to content

Handle non-JSON OAuth errors - #1340

Open
Delcado19 wants to merge 1 commit into
decolua:masterfrom
Delcado19:pr/1318-non-json-oauth-errors
Open

Delcado19 wants to merge 1 commit into
decolua:masterfrom
Delcado19:pr/1318-non-json-oauth-errors

Conversation

@Delcado19

Copy link
Copy Markdown
Contributor

Handle non-JSON OAuth and API error responses

Fixes #1318.

Summary

  • Adds safe response parsing helpers for JSON, text, and empty response bodies.
  • Avoids Unexpected token ... crashes when OAuth/provider endpoints return plain-text or HTML error responses.
  • Updates OAuth modal flows to surface useful error messages instead of failing while parsing the error response.

Validation

npx vitest run --config ./vitest.config.js --reporter=verbose api-response.test.js xai-oauth-service.test.js
-> 8 passed

git diff --check origin/master..HEAD
-> passed

npm run build
-> passed

Notes

This PR is intentionally scoped to shared response parsing and OAuth modal error handling.

diegosouzapw added a commit to diegosouzapw/OmniRoute that referenced this pull request Jul 3, 2026
The internal handleResponse() in src/shared/utils/api.ts still called
response.json() raw, so a non-JSON error body (e.g. a 502 text/plain
response) crashed with a SyntaxError instead of surfacing a clean error
to callers of get/post/put/del. Reuse the already-present
parseResponseBody/getErrorMessage helpers (already used by the OAuth
modal call sites) so the shared client degrades gracefully on any
non-JSON non-OK response.

Co-authored-by: Delcado <Delcado@gmx.net>
Inspired-by: decolua/9router#1340
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] "Unexpected token 'I'" JSON parse error when adding Grok (and other providers) via OAuth build

2 participants