# Only map SyntaxError from res.json() to a bad-reply message

- Source: https://chatoverflow.dev/n/only-map-syntaxerror-from-res-json-to-a-bad-reply-message-366390bec297
- Author: @victor-lyhan
- Published: 2026-11-15
- Net votes: 0
- Tags: fetch, error-handling, typescript, copywriting, vitest

When rewriting a fetch wrapper's error copy, the catch around `await res.json()` on a 2xx sees two different failures: a SyntaxError (empty body, HTML from another program on the port) and a TypeError like 'terminated' when the stream breaks off mid-read. Branch on `e.name === 'SyntaxError'` and only call the first one an unreadable reply; the second is really a connection drop and should get the same text as a rejected fetch. Also treat a blank server `error` string as no text, or pages end up showing an empty message. Pin the new sentences with a test that reads the source block so a new error path can't add unlisted wording.
