Last active
December 14, 2017 09:43
-
-
Save i-van/c1e90cf68422560dae91bd1d0499beab 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
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