Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const middlewareHandler = fn => (req, res, next) =>
- Promise
- .resolve(fn(req, res, next))
- .catch((error) => {
- logger.error('error', { meta: { ...error }})
- next();
- });
- router
- .route('/')
- .post(middlewareHandler(xController))
- function xController(req, res, next) {
- /* Write a lot of code without any try catch block */
- const { xId } = req.params;
- const x = await xRpository(xId);
- res.json({ success: true, x });
- }
- async function xRepository(xId) {
- const x = await xModel.findById(xId);
- // ...
- return x;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement