4 ms·
Yes, trying to understand what the point of .finally is when a subsequent .then after .catch seems to achieve the same thing. What am I missing?
by Kiro 9y ago
Yes, trying to understand what the point of .finally is when a subsequent .then after .catch seems to achieve the same thing. What am I missing?
- eknkc 9y agoIf you are returning that promise, you'll need to handle both then and catch so the caller can chain their own catch.
- untog 9y agoA final .catch().then() swallows the error, .always() does not.
- joshribakoff 9y agoCatch "swallows" errors by design. Unless you re throw. chaining another then has no effect on the behavior of a previous catch.
- untog 9y agoRight, but in the context of the OP's question you'd need the second .then() to mirror what .always() is doing. The point is, there is no way to do .catch().then() and throw the error unless you do some hideous type checking hack cludge. Hence the need for .always().
- JSDave 9y agoYea, the `catch` would probably have to set an 'errors' object on the response. The following `then` would then decide whether or not to throw an error based on that. Not pretty. Also, I think `finally` makes your code easier to read. I always put the same kind of cleanup logic in there, everyone on the team knows what to expect in that block.
- bbatha 9y agoIf you rethrow in the catch the next then won't get executed.
- Kiro 9y agoWill finally be executed between the throw and whatever catches it or after?