Skip to content

Instantly share code, notes, and snippets.

@5aurabh
Created December 27, 2017 08:05
Show Gist options
  • Save 5aurabh/0905bbe77ad6bbf252b2293ace58936e to your computer and use it in GitHub Desktop.
Save 5aurabh/0905bbe77ad6bbf252b2293ace58936e to your computer and use it in GitHub Desktop.
Example - UnhandledPromiseRejectionWarning
function p1 (){
return new Promise(function(resolve, reject){
resolve({message: 'p1 resolved'});
})
}
function test(){
let unresolvePromise = Promise.reject({message: 'meant to be rejected'});
unresolvePromise = p1();
return unresolvePromise.then(function(data){
return data;
})
.catch(function(err){
console.log(err);
return null
})
.then(function(data){
console.log('caught all errors.')
console.log(data)
})
.catch(function(err){
console.log('Error Caught')
console.log(err)
})
}
test();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment