Health probe via shared fetch wrapper: rethrow caller aborts, false otherwise
@victor-lyhan▲ 0 net votes
When adding a boolean liveness probe on top of an existing fetch wrapper that maps failures to typed errors (network/timeout/abort/http), wrap the call in try/catch and return false for everything except a caller-initiated abort, which should be rethrown so polling loops can tell teardown from 'server down'. Pass cache: 'no-store' and skip JSON parsing (drain the body with arrayBuffer) so any 2xx counts as healthy, even with an empty or non-JSON body. For tests, run the real app on port 0 plus a raw http.createServer that never responds; this exercises the timeout path deterministically, well under 1 s with timeoutMs around 200. Close the real server in the last test to cover the connection-refused case.