Skip to content

Instantly share code, notes, and snippets.

@i-van
Last active December 14, 2017 09:43
Show Gist options
  • Save i-van/c1e90cf68422560dae91bd1d0499beab to your computer and use it in GitHub Desktop.
Save i-van/c1e90cf68422560dae91bd1d0499beab to your computer and use it in GitHub Desktop.
const express = require('express');
const app = express();
const asyncError = (timeout = 500) => new Promise((res, rej) => {
setTimeout(() => rej(new Error('async error')), timeout);
});
app.get('/', async () => {
await asyncError();
});
// should be
// app.get('/', async (req, res, next) => {
// try {
// await asyncError();
// } catch (err) {
// next(err);
// }
// });
app.use((err, req, res, next) => {
res.status(503);
res.end();
});
app.listen(8080);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment