1
0
mirror of synced 2025-12-23 11:54:18 -05:00
Files
docs/middleware/abort.js
Mike Surowiec 83e33cc9bb Quiet sass warnings (#19960)
* npm install sass@latest

* add quietDeps: true to webpack config

* prevent error message from hmr abort, cleans up the log

Co-authored-by: Sarah Schneider <sarahs@github.com>
2021-06-16 19:47:01 +00:00

20 lines
564 B
JavaScript

module.exports = 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()
}