SHARE
TWEET

Untitled

a guest Sep 20th, 2019 81 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. async function startTask(req) {
  2.  
  3.   const {
  4.     params: {
  5.       userId,
  6.     },
  7.   } = req;
  8.  
  9.   const user = await getUser(userId)
  10.     .catch((e) => {
  11.       throw new Error('A better error');
  12.     });
  13.  
  14.   const newTask = await createTask({
  15.     userId,
  16.     name: 'Another task',
  17.   })
  18.     .catch((e) => {
  19.       throw new Error('I like this error better than the "createTask" error');
  20.     });
  21.  
  22.   await sendNotification()
  23.     .catch((e) => {
  24.       throw new Error('Uh oh');
  25.     });
  26.  
  27.   await sendNotification()
  28.     .catch((e) => {
  29.       throw new Error('Uh oh again!');
  30.     });
  31.  
  32.   return newTask;
  33. }
  34.  
  35.  
  36. function callsStartTask() {
  37.  
  38.   startTask(req)
  39.     .then(newTask => {
  40.  
  41.       res.send(newTask)
  42.  
  43.     })
  44.     .catch((e) => {
  45.  
  46.       res.status(e.statusCode).send(e.message)
  47.  
  48.     })
  49.  
  50. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top