Skip to content

feat: expose the HTTP response on failed JSON GET requests - #2483

Open
mercer wants to merge 2 commits into
authts:mainfrom
mercer:feat/discovery-http-error
Open

mercer wants to merge 2 commits into
authts:mainfrom
mercer:feat/discovery-http-error

Conversation

@mercer

@mercer mercer commented Nov 19, 2026 •

Copy link
Copy Markdown

When discovery returns HTTP 429, applications need the status and Retry-After header to schedule the next attempt. A gateway can send plain text or an empty body. Parsing the exception message then loses the status or the cooldown.

This change exposes the original Fetch response on failures from JSON GET requests. Generic HTTP failures throw the exported ErrorHttpResponse. An OAuth error document still throws ErrorResponse, so existing catch blocks keep working; it carries the response on a property of the same name, so a caller can read error.response without checking which class it caught. Existing error messages are preserved, including "Invalid response Content-Type" for a non-JSON reply, so read response.status rather than the message. The response cannot pass through structuredClone or postMessage.

Scope: this covers getJson only. postForm (the token endpoint) still throws a plain Error for these cases and is left for a follow-up. The new third ErrorResponse parameter sits after form so that follow-up can pass both.

Five regression cases in JsonService.test.ts exercise getJson() with plain text, malformed JSON, an empty object, JSON null and an OAuth error document. They check the message, the error class and the identity of the response. The full test suite, lint and package build pass.

  • Updated the public API report.

@mercer mercer closed this Nov 19, 2026
@mercer
mercer deleted the feat/discovery-http-error branch November 19, 2026 14:33
@mercer
mercer restored the feat/discovery-http-error branch November 19, 2026 14:34
@mercer mercer reopened this Nov 19, 2026
Move the five 429 cases from MetadataService.test.ts to the getJson
tests, where the behaviour lives, and assert the error class. Give
ErrorHttpResponse the same "Marker to detect class" name field as
ErrorTimeout and ErrorDPoPNonce, and document that callers should read
response.status and that the response cannot be cloned.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017JuHv1wUFSRq7LQyDkjuC9

This branch has not been deployed

No deployments
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.

1 participant