Created
July 24, 2016 21:26
-
-
Save Colorfulstan/2fbc4d55aa38d80fd53d7eefbd305320 to your computer and use it in GitHub Desktop.
silently failing promises
https://plnkr.co/edit/EvXPqjzobbwejTJcSKJO?p=previe
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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