A throw nobody catches
Watch what the client gets when an async handler throws.
const http = require('node:http');process.on('unhandledRejection', (err) => console.log('unhandled: ' + err.message));const server = http.createServer(async (req, res) => { console.log('handler starts'); throw new Error('db down');});server.listen(0, async () => { const { port } = server.address(); try { await fetch(`http://localhost:${port}`, { signal: AbortSignal.timeout(200) }); } catch (err) { console.log('client: ' + err.name); } server.closeAllConnections(); server.close();});1. Predict the output
Tap the lines in the order you think they print.
- 1…
- 2…
- 3…