Skip to content

Instantly share code, notes, and snippets.

@dannycroft
Created June 11, 2019 14:02
Show Gist options
  • Save dannycroft/74d4afe829d19c8a124c49f5daee6bd3 to your computer and use it in GitHub Desktop.
Save dannycroft/74d4afe829d19c8a124c49f5daee6bd3 to your computer and use it in GitHub Desktop.
/* ------------------------------- */
/* 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