1
0
mirror of synced 2025-12-21 02:46:50 -05:00
Files
docs/middleware/abort.js
Kevin Heis 8a56437c93 Pretty format (#20352)
* Update prettier flow to include JS

* Run prettier

* ...run prettier
2021-07-14 14:35:01 -07:00

20 lines
561 B
JavaScript

export default function abort(req, res, next) {
// If the client aborts the connection, send an error
req.once('aborted', () => {
// ignore aborts from next, usually has to do with webpack-hmr
if (req.path.startsWith('/_next')) {
return
}
// NOTE: Node.js will also automatically set `req.aborted = true`
const abortError = new Error('Client closed request')
abortError.statusCode = 499
abortError.code = 'ECONNRESET'
// Pass the error to the Express error handler
return next(abortError)
})
return next()
}