Guest User

Untitled

a guest
Dec 16th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. const express = require('express');
  2.  
  3. const app = express();
  4.  
  5. const asyncError = (timeout = 500) => new Promise((res, rej) => {
  6. setTimeout(() => rej(new Error('async error')), timeout);
  7. });
  8.  
  9. app.get('/', async () => {
  10. await asyncError();
  11. });
  12.  
  13. // should be
  14.  
  15. // app.get('/', async (req, res, next) => {
  16. // try {
  17. // await asyncError();
  18. // } catch (err) {
  19. // next(err);
  20. // }
  21. // });
  22.  
  23. app.use((err, req, res, next) => {
  24. res.status(503);
  25. res.end();
  26. });
  27.  
  28. app.listen(8080);
Add Comment
Please, Sign In to add comment