1
0
mirror of synced 2025-12-19 18:10:59 -05:00
Files
docs/middleware/trigger-error.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

14 lines
553 B
JavaScript

// This module is for testing our handling of uncaught async rejections on incoming requests
// IMPORTANT: Leave this function as `async` even though it doesn't need to be!
module.exports = async function triggerError (req, res, next) {
// IMPORTANT:
// Do NOT wrap this method's contents in the usual `try-catch+next(error)`
// pattern used on async middleware! This is an intentional omission!
// prevent this from being used in production
if (process.env.NODE_ENV === 'production') return next()
throw new Error('Intentional error')
}