Javascript promise error handling tricks

Jeff shared some JS Promise wisdom.

(1) If you use promises, end with a .then(null, your_error_handler) so that any errors in any previous success handler  are caught.  Otherwise the error will be lost–it won’t even show up in the console.  This can be very annoying for debugging!  Note that .then(your_success_handler, your_error_handler) is not the same: in that spelling, if your_success_handler fails, the error will again be dumped on the floor, rather than passed to your_error_handler.

(2) If you use promises in a test, have the tested function return the promise so that you can say .then(your_assertion_function, done).  The “done” is the important new information in Jeff’s hint: it keeps the test from hanging on error.