1
0
mirror of synced 2025-12-22 11:26:57 -05:00
Files
docs/middleware/abort.js
James M. Greene c940dcd98b Middleware overhaul! (#18218)
* Middleware overhaul!

- Remove unnecessary 'async' keywords from middleware functions
- Ensure all middleware functions we create have names
- Wrap the method contents of all async middleware functions in a try-catch+next(error) pattern

* Use asyncMiddleware wrapper instead of try-catch+next(error) pattern

* Remove unnecessary try-catch+next(error) pattern from context middleware
2021-03-11 01:12:41 +00:00

16 lines
437 B
JavaScript

module.exports = function abort (req, res, next) {
// If the client aborts the connection, send an error
req.once('aborted', () => {
// 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()
}