Reputation: 59525
Are these two code blocks the same? I'm looking to open up .catch()
and log the error but I still want the error to be "uncaught", can I just return it? Or does it need to be wrapped in a Promise.reject()
?
Block A:
soSomething()
.then(() => {
return "meow"
})
.catch(() => {
console.log(err)
return err
})
Block B:
soSomething()
.then(() => {
return "meow"
})
.catch(() => {
console.log(err)
return Promise.reject(err)
})
Upvotes: 0
Views: 24
Reputation: 1
The two patterns are not the same.
The first handles the error and returns a resolved Promise
, reaching the first function parameter at a chained .then()
.
The second example returns a rejected Promise
, reaching the second function parameter at a chained .then()
or .catch()
.
I'm looking to open up
.catch()
and log the error but I still want the error to be "uncaught", can I just return it?
The first pattern should meet requirement.
Upvotes: 3