Created
June 11, 2019 14:02
-
-
Save dannycroft/74d4afe829d19c8a124c49f5daee6bd3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* ------------------------------- */ | |
/* common/errorHandler.js */ | |
/* ------------------------------- */ | |
const asyncUtil = fn => | |
function asyncUtilWrap(...args) { | |
const fnReturn = fn(...args) | |
const next = args[args.length-1] | |
return Promise.resolve(fnReturn).catch(next) | |
} | |
export default asyncUtil; | |
/* ------------------------------- */ | |
/* server.js */ | |
/* ------------------------------- */ | |
app.get('/', asyncMiddleware(async (req, res, next) => { | |
const html = await renderHtml(req.body); | |
res.send(user) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment