* 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
16 lines
437 B
JavaScript
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()
|
|
}
|