Skip to content

feat: surface HTTP status code in onNext metadata#61

Merged
robrichard merged 1 commit into
relay-tools:masterfrom
mjfaga:feat/onnext-http-status
Jun 25, 2026
Merged

feat: surface HTTP status code in onNext metadata#61
robrichard merged 1 commit into
relay-tools:masterfrom
mjfaga:feat/onnext-http-status

Conversation

@mjfaga

@mjfaga mjfaga commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Fixes #60

onNext already receives a metadata arg ({ responseHeaders } on the fetch transport), but not the HTTP status. A non-2xx JSON response (e.g. a 401) parses successfully, so it is delivered through onNext — not onError — with the status discarded. Consumers therefore cannot distinguish a 401 from a normal GraphQL response and cannot react to auth failures.

Add status to the onNext metadata on both transports:

  • fetch.js: response.status (multipart onResponse + json branches)
  • xhr.js: xhr.status (multipart onResponse + json branch)
  • typings.d.ts: type the previously-untyped onNext metadata arg ({ responseHeaders?: Headers; status?: number }).

onNext already receives a metadata arg ({ responseHeaders } on the fetch
transport), but not the HTTP status. A non-2xx JSON response (e.g. a 401)
parses successfully, so it is delivered through onNext — not onError — with
the status discarded. Consumers therefore cannot distinguish a 401 from a
normal GraphQL response and cannot react to auth failures.

Add `status` to the onNext metadata on both transports:
- fetch.js: response.status (multipart onResponse + json branches)
- xhr.js: xhr.status (multipart onResponse + json branch)
- typings.d.ts: type the previously-untyped onNext metadata arg
  ({ responseHeaders?: Headers; status?: number }).
@robrichard robrichard merged commit da727d7 into relay-tools:master Jun 25, 2026
6 checks passed
@robrichard

Copy link
Copy Markdown
Member

Thanks!

robrichard pushed a commit that referenced this pull request Jun 29, 2026
onNext already receives a metadata arg ({ responseHeaders } on the fetch
transport), but not the HTTP status. A non-2xx JSON response (e.g. a 401)
parses successfully, so it is delivered through onNext — not onError — with
the status discarded. Consumers therefore cannot distinguish a 401 from a
normal GraphQL response and cannot react to auth failures.

Add `status` to the onNext metadata on both transports:
- fetch.js: response.status (multipart onResponse + json branches)
- xhr.js: xhr.status (multipart onResponse + json branch)
- typings.d.ts: type the previously-untyped onNext metadata arg
  ({ responseHeaders?: Headers; status?: number }).
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.

Expose HTTP status code in onNext metadata

2 participants