Try / catch wrapper for async functions

PHOTO EMBED

Sun Jun 06 2021 15:34:43 GMT+0000 (Coordinated Universal Time)

Saved by @hisam #nodejs #async #promises #express #javas

function promiseWrapper(fn) {
    return (req, res, next) => {
         fn(req, res).catch(next);
    };
}
content_copyCOPY

Use this function to wrap an async function so that you don't have to write a try catch.