Lesson 7 of 8
Promise errors
- 13 min
- 4 checks
- 3 hints
- Go to task
Goal
What you don't await, you can't catch
Explanation
A try/catch block only catches what is thrown inside it. A promise you don't await rejects later, after execution has already left the block, so catch never sees it, and you end up with a page that says "Saved." even though saving failed.
The fix is one word: await inside try. The rejection then becomes an ordinary error thrown from that same line, and it reaches catch.
Sometimes you deliberately don't wait, like when you send an analytics event that isn't worth delaying the user for. But a rejection nobody handles doesn't disappear: it shows up in the console as an "unhandled rejection" and its cause gets lost. That's why every promise you don't await needs its own .catch.
Your task
Fix save() so that #msg shows the real reason for a failure and success is never announced before it happens, then handle the rejection from track without awaiting it.
Checks
4 checks- A failed save doesn't look like a success
- The failure message gives the real reason
- Success isn't announced before it happens
- No rejection goes unhandled