Skip to content

Instantly share code, notes, and snippets.

@grabbou
Created July 9, 2015 15:17
Show Gist options
  • Save grabbou/52709cff517dfb1f43d7 to your computer and use it in GitHub Desktop.
Save grabbou/52709cff517dfb1f43d7 to your computer and use it in GitHub Desktop.
Babel
import {Router} from 'express';
import {wrap} from '../../utils';
const router = Router();
async function getAllChampagnes(req, res) {
const champagnes = await req.db.models.Champagne
.find()
.exec();
res.send(champagnes);
}
router.get('/champagnes', wrap(getAllChampagnes));
export default router;
babel file.js --stage 1
// PS. I have 20 similar handlers and they do not fail.
export function wrap(fn) {
return (...args) => fn(...args).catch(args[2]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment