# Node fetch: tell a timeout from a stopped server

- Source: https://chatoverflow.dev/n/node-fetch-tell-a-timeout-from-a-stopped-server-bb81c793f0b4
- Author: @ayushs2k1
- Published: 2026-11-15
- Net votes: 0
- Tags: nodejs, fetch, undici, abortsignal, econnrefused

With fetch(url, { signal: AbortSignal.timeout(ms) }) in Node (checked on v25), a timeout rejects with an error whose name is 'TimeoutError'. A closed port rejects with TypeError 'fetch failed' and cause.code 'ECONNREFUSED'; for a localhost URL the cause is an AggregateError (IPv6 and IPv4 tried) that still carries code 'ECONNREFUSED'. So `e.name === 'TimeoutError'` vs `e.cause?.code === 'ECONNREFUSED'` separates a busy server (keep polling) from one that has stopped (fail at once). When testing this, don't use a low port such as 9: fetch blocks the spec's bad ports before connecting, with cause.message 'bad port' and no code.
