Skip to content

Treat response deserialization failures as request errors - #33

Merged
ejsmith merged 1 commit into
mainfrom
fix/response-deserialization-errors
Jul 28, 2026
Merged

Treat response deserialization failures as request errors#33
ejsmith merged 1 commit into
mainfrom
fix/response-deserialization-errors

Conversation

@ejsmith

@ejsmith ejsmith commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Summary

  • preserve the original abort reason when a signal cancels a successful response body read
  • throw a new exported FetchClientDeserializationError when a successful response body cannot be read or parsed as JSON
  • keep malformed non-success responses on the existing RFC 7807/status-error path
  • run deserialization failures through middleware and errorCallback, avoid caching them, and always clear request loading counters
  • document the behavior change and add regressions for abort-during-body-read and malformed 2xx JSON

Root cause

getJSONResponse caught body-read and JSON parsing failures and assigned a generated ProblemDetails instance to response.data. Because the original HTTP response could still have ok === true, callers and query libraries treated that problem object as successful typed data.

Behavior change

Successful responses with invalid JSON now reject with FetchClientDeserializationError. The error exposes the underlying FetchClientResponse, parsing/reading cause, and responseText. Caller cancellation is not wrapped: the request rejects with the signal's original abort reason. shouldThrowOnUnexpectedStatusCodes remains limited to HTTP status handling. An errorCallback can still explicitly suppress a deserialization error by returning true, in which case data is null rather than ProblemDetails.

Actual non-success HTTP responses continue to populate response.problem and use existing status handling.

Validation

  • deno task format-check
  • deno task lint
  • deno task check
  • deno task test — 200 passed
  • deno task build --set-version 0.0.0 --allow-dirty
  • verified the generated package exports FetchClientDeserializationError
  • git diff --check

Closes #31

@ejsmith
ejsmith marked this pull request as ready for review July 28, 2026 23:47
@ejsmith
ejsmith merged commit b053976 into main Jul 28, 2026
4 checks passed
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.

Treat response deserialization failures as request errors

1 participant