Skip to content

Gracefully catch unexpected html (non json) response from external services#6873

Merged
alfonso-noriega merged 1 commit intomainfrom
1325-error-unexpected-token-htmlh-is-not-valid-json
Feb 24, 2026
Merged

Gracefully catch unexpected html (non json) response from external services#6873
alfonso-noriega merged 1 commit intomainfrom
1325-error-unexpected-token-htmlh-is-not-valid-json

Conversation

@alfonso-noriega
Copy link
Copy Markdown
Contributor

@alfonso-noriega alfonso-noriega commented Feb 20, 2026

WHY are these changes introduced?

Issue #1325

Vault error

Observe error

JSON parsing errors in HTTP responses were causing unhandled exceptions and poor error messages when external services return malformed responses or are temporarily unavailable.

WHAT is this pull request doing?

Add proper error handling for JSON parsing failures in HTTP response processing across three modules:

  • Token exchange service: Wrap JSON parsing in try-catch and throw descriptive AbortError when identity service returns invalid JSON
  • GitHub API client: Handle JSON parsing errors when fetching release information and provide clear error messaging
  • Admin authentication: Add error handling for malformed responses from the admin authentication service

All error messages inform users that the service may be temporarily unavailable and suggest retrying.

Measuring impact

How do we know this change was effective? Please choose one:

  • n/a - this doesn't need measurement, e.g. a linting rule or a bug-fix
  • Existing analytics will cater for this addition
  • PR includes analytics changes to measure impact

Checklist

  • I've considered possible cross-platform impacts (Mac, Linux, Windows)
  • I've considered possible documentation changes

Copy link
Copy Markdown
Contributor Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@alfonso-noriega alfonso-noriega force-pushed the 1325-error-unexpected-token-htmlh-is-not-valid-json branch 3 times, most recently from 50808c2 to 9d4ac4e Compare February 20, 2026 17:24
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Feb 20, 2026

Coverage report

St.
Category Percentage Covered / Total
🟡 Statements 78.79% 14490/18391
🟡 Branches 73.13% 7203/9850
🟡 Functions 79.01% 3686/4665
🟡 Lines 79.13% 13698/17311

Test suite run success

3767 tests passing in 1448 suites.

Report generated by 🧪jest coverage report action from 6b9e797

@alfonso-noriega alfonso-noriega marked this pull request as ready for review February 20, 2026 17:55
@alfonso-noriega alfonso-noriega requested a review from a team as a code owner February 20, 2026 17:55
@github-actions
Copy link
Copy Markdown
Contributor

We detected some changes at packages/*/src and there are no updates in the .changeset.
If the changes are user-facing, run pnpm changeset add to track your changes and include them in the next release CHANGELOG.

Caution

DO NOT create changesets for features which you do not wish to be included in the public changelog of the next CLI release.

@alfonso-noriega alfonso-noriega force-pushed the 1325-error-unexpected-token-htmlh-is-not-valid-json branch 3 times, most recently from e54bc82 to 956932e Compare February 24, 2026 12:14
Copy link
Copy Markdown
Contributor

@gonzaloriestra gonzaloriestra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, thanks!

Just a few minor suggestions.

Comment thread packages/cli-kit/src/private/node/session/exchange.ts Outdated
Comment thread packages/cli-kit/src/private/node/session/exchange.ts Outdated
Comment thread packages/cli-kit/src/private/node/session/exchange.ts Outdated
@alfonso-noriega alfonso-noriega force-pushed the 1325-error-unexpected-token-htmlh-is-not-valid-json branch from 956932e to 6b9e797 Compare February 24, 2026 16:16
@alfonso-noriega alfonso-noriega added this pull request to the merge queue Feb 24, 2026
Merged via the queue into main with commit 3a41f49 Feb 24, 2026
44 of 45 checks passed
@alfonso-noriega alfonso-noriega deleted the 1325-error-unexpected-token-htmlh-is-not-valid-json branch February 24, 2026 17:00
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.

2 participants