TIL: If you accidentally use a promise.then (instead of await) in an async...


TIL: If you accidentally use a promise.then (instead of await) in an async function, the catch block won't get called on error!

The code on the left never fell into the catch on error because it was using .then instead of await. Easy mistake to make.

#javascript

This makes sense. With promise.then, you handle errors via .catch. This rule still applies when you're in an async func.

So for the catch block to work, you must use the async keyword instead of .then.

View original on X