-
-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use promise then() instead of catch() with callbacks #1679
Conversation
Addresses my review here: #1419 (review)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although I think the bigger improvements for readability are
- inline variables
string=${x}
instead of concatenations like"string=" + x
- getting rid of redundant
return
- and
function (x)
tox =>
@Borewit These changes weren't about readability but about correctness. The |
I honestly don't see the difference Ferros.
|
@Borewit There's a difference. See https://stackoverflow.com/a/33278420/292185 Let me know if it still doesn't make sense and I'll try to explain further. |
Ah yes, you are right Feross! I completely missed the point. catch(errorCallback)` is an alias for then(null, errorCallback) where the alias is appended and not instead of the error handler of the previous then (should say the promise it is calling). |
This has an interesting behavior: const p1 = new Promise((resolve, reject) => {
throw(new Error('Promise 1 THROWN'))
})
const p2 = new Promise((resolve, reject) => {
setTimeout(() => {
throw(new Error('Promise 2 THROWN'))
})
})
p1
.then(null, message => console.log('P1 failed:', message))
.catch(message => console.log('P1 catched:', message))
p2
.then(null, message => console.log('P2 failed:', message))
.catch(message => console.log('P2 catched:', message)) You can run it here. |
What is the purpose of this pull request? (put an "X" next to item)
[ ] Documentation update
[x] Bug fix
[ ] New feature
[ ] Other, please explain:
What changes did you make? (Give an overview)
Addresses my review here: #1419 (review)
Is there anything you'd like reviewers to focus on?