1
00:00:01,546 --> 00:00:03,435
When handling errors with promises, you

2
00:00:03,435 --> 00:00:06,573
only had to attach a catch function, but

3
00:00:06,573 --> 00:00:09,545
how do you handle errors with async/await?

4
00:00:09,545 --> 00:00:11,725
Head back to the code and copy the get

5
00:00:11,725 --> 00:00:16,583
function code into the getCatch function,

6
00:00:16,583 --> 00:00:18,688
and make sure that the getCatch function

7
00:00:18,688 --> 00:00:21,077
is async, so you don't get that same

8
00:00:21,077 --> 00:00:23,296
reserved word error that we got in the

9
00:00:23,296 --> 00:00:25,226
last clip. As we did with our promise

10
00:00:25,226 --> 00:00:28,281
code, change the route to getOrder123,

11
00:00:28,281 --> 00:00:30,924
because that'll produce an error for us.

12
00:00:30,924 --> 00:00:32,662
In the last clip, I promised you that it's

13
00:00:32,662 --> 00:00:35,024
a familiar way to handle the error. You

14
00:00:35,024 --> 00:00:36,480
want to take a guess at maybe what that

15
00:00:36,480 --> 00:00:39,872
way is? Well, believe it or not, this is

16
00:00:39,872 --> 00:00:41,939
one place where it's not really related to

17
00:00:41,939 --> 00:00:44,955
promises, that is, there's not an awake

18
00:00:44,955 --> 00:00:49,866
catch function. Instead, it's the tried

19
00:00:49,866 --> 00:00:54,422
and true try-catch block. If you reload

20
00:00:54,422 --> 00:00:56,316
the website and click the Handle Errors

21
00:00:56,316 --> 00:00:59,789
button, you'll see a familiar 404 error in

22
00:00:59,789 --> 00:01:02,804
the response text, and you'll notice the

23
00:01:02,804 --> 00:01:05,944
standard 404 error in the console as well.

24
00:01:05,944 --> 00:01:08,846
That shows that we're handling our promise

25
00:01:08,846 --> 00:01:10,298
rejection. Looking at this code one last

26
00:01:10,298 --> 00:01:12,107
time, notice that since the error handling

27
00:01:12,107 --> 00:01:14,737
is the standard JavaScript try-catch

28
00:01:14,737 --> 00:01:17,304
block, you now have the ability to have

29
00:01:17,304 --> 00:01:20,122
the same error handling for both your

30
00:01:20,122 --> 00:01:23,242
synchronous and asynchronous code if

31
00:01:23,242 --> 00:01:25,947
you're using async/await. Earlier we saw

32
00:01:25,947 --> 00:01:28,523
how promises can be chained to combat race

33
00:01:28,523 --> 00:01:30,181
conditions. In the next clip, I'll show

34
00:01:30,181 --> 00:01:34,000
you how to accomplish the same thing with async/await.

