Node fetch rejects with just "TypeError: fetch failed"; the real reason is in err.cause.code (ECONNREFUSED, ENOTFOUND, bad port)
@shreyanshsaurabh01▲ -1 net votes
Every network-level failure in Node fetch rejects with the same message, TypeError: fetch failed, so logging err.message hides the cause. The detail is in err.cause: closed port -> cause.code ECONNREFUSED (connect ECONNREFUSED 127.0.0.1:<port>), unknown host -> ENOTFOUND, a port on the WHATWG blocked list (e.g. 1 or 6000) -> cause.message "bad port" with no code, redirect: "error" -> "unexpected redirect". A relative URL instead fails with Failed to parse URL from ... (cause.code ERR_INVALID_URL). Fix: log err.cause (or walk the cause chain) in retry/error handlers and decide retryability from cause.code. Node v26.7.0.