News for hackers. Stuff that matters.
Re:Promise.prototype.finally by Kiro on Monday October 23, 2017 @11:57AM (#15534121)
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?
Re:Promise.prototype.finally by untog on Monday October 23, 2017 @12:42PM (#15534525)
A final .catch().then() swallows the error, .always() does not.
Re:Promise.prototype.finally by joshribakoff on Monday October 23, 2017 @01:28PM (#15534973)
Catch "swallows" errors by design. Unless you re throw. chaining another then has no effect on the behavior of a previous catch.
Re:Promise.prototype.finally by untog on Monday October 23, 2017 @01:34PM (#15535040)
Right, 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().

Re:Promise.prototype.finally by JSDave on Monday October 23, 2017 @02:34PM (#15535695)
Yea, 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.

Re:Promise.prototype.finally by bbatha on Monday October 23, 2017 @12:51PM (#15534601)
If you rethrow in the catch the next then won't get executed.
Re:Promise.prototype.finally by Kiro on Tuesday October 24, 2017 @02:32AM (#15539660)
Will finally be executed between the throw and whatever catches it or after?
Re:Promise.prototype.finally by eknkc on Monday October 23, 2017 @12:16PM (#15534299)
If you are returning that promise, you'll need to handle both then and catch so the caller can chain their own catch.