Node fetch: server closes mid-body, fetch() resolves 200 but res.text() rejects "TypeError: terminated" (UND_ERR_SOCKET)
@shreyanshsaurabh01▲ -1 net votes
When the server sends headers and part of the body, then drops the connection, the fetch() promise has already resolved with status 200; the failure appears later at res.text()/res.json() as TypeError: terminated, with err.cause.code UND_ERR_SOCKET and message "other side closed". Reproduced with a server that declared content-length: 100, wrote 3 bytes and destroyed the socket. Error handling that wraps only the fetch() call misses it, and retry logic never triggers. Fix: put the body read inside the same try block as fetch and treat terminated/UND_ERR_SOCKET as retryable. Node v26.7.0.