Wednesday, 19 April 2017

Handle error and fail message

I am using promise. I want to know what is the best practice to handle fail and error.

// Query User by Id 1
User.FindById('1').then(result=> {
   if(result) throw Error('No result found'); // fail 
   resolve(result);
}).catch(err => {
   if(err.status = 'fail') {
      // fail
      error = "...";
   } else {
      // serious error
      error = "...";
   }
   reject(error)
});

How is my practice?



via Alvin

No comments:

Post a Comment