Skip to content

Instantly share code, notes, and snippets.

@Colorfulstan
Created July 24, 2016 21:26
Show Gist options
  • Save Colorfulstan/2fbc4d55aa38d80fd53d7eefbd305320 to your computer and use it in GitHub Desktop.
Save Colorfulstan/2fbc4d55aa38d80fd53d7eefbd305320 to your computer and use it in GitHub Desktop.
console.log('Don\'t nest promises with catch without knowing what you are doing!');
new Promise(function(resolve1, reject1){
reject1('This is fine');
})
new Promise(function(resolve2, reject2){
return new Promise(function(resolve2Inner, reject2Inner){
reject2Inner('This is also fine');
})
})
//////////////////////////////////////////////////////////////////////////////////
new Promise(function(resolve2, reject2){
return new Promise(function(resolve2Inner, reject2Inner){
reject2Inner('This would be fine');
}).catch(function(){
console.warn('If not caught without propagation');
})
}).catch(function(){
console.log('this will catch nothing')
})
//////////////////////////////////////////////////////////////////////////////////
new Promise(function(resolve2, reject2){
return new Promise(function(resolve2Inner, reject2Inner){
reject2Inner('So always make sure');
}).catch(function(err){
return Promise.reject(err);
})
}).catch(function(err){
throw new Error(err + 'to propagate errors to the top');
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment