1
00:00:00,120 --> 00:00:01,950
So let's navigate the app context.

2
00:00:02,340 --> 00:00:07,470
Let's scroll up, first of all, let me it just so you don't think that I'm cheating, just so you know,

3
00:00:07,470 --> 00:00:11,050
that is definitely going to be added with our interceptors.

4
00:00:11,790 --> 00:00:13,920
And I guess let's set up the request on force.

5
00:00:13,930 --> 00:00:20,640
So and then I'm going to go with my offer switch, not interceptors when we want to go with the request

6
00:00:20,640 --> 00:00:21,750
one we can use.

7
00:00:21,750 --> 00:00:24,630
And then as we saw in the docs, we want to pass here two functions.

8
00:00:24,900 --> 00:00:30,540
So let me set up this one right from the get go and then we'll worry about the rest of the stuff.

9
00:00:30,540 --> 00:00:36,540
So and once I have them in place for the first one, I need to come up with some kind of parameter.

10
00:00:36,540 --> 00:00:41,370
In my case, that is going to be config, just like in the box, and we want to return that config.

11
00:00:41,820 --> 00:00:45,540
So let's first start by pretending otherwise, it's very easy to forget.

12
00:00:45,900 --> 00:00:51,720
And then we go with config, then headers, then that and then common and right after common.

13
00:00:51,960 --> 00:00:58,680
I want to go with my authorization just like we had in our global setup, and that one will be equal

14
00:00:58,680 --> 00:01:00,150
again to our token.

15
00:01:00,670 --> 00:01:01,410
So better.

16
00:01:01,740 --> 00:01:06,060
And then what's access the state and then token?

17
00:01:06,420 --> 00:01:10,230
And as far as the response error, it's pretty much going to be generic.

18
00:01:10,230 --> 00:01:11,910
So we're going to go with error.

19
00:01:12,580 --> 00:01:16,110
And then we want to go with a turn that promise.

20
00:01:17,150 --> 00:01:21,710
That and a reject, and let's pass here are as well.

21
00:01:22,150 --> 00:01:22,940
Let's save it.

22
00:01:23,300 --> 00:01:27,890
And in order to speed this up a little bit, I'm going to copy and paste everything like so.

23
00:01:29,020 --> 00:01:30,820
And this is going to be for response.

24
00:01:31,240 --> 00:01:32,890
So one by one, let's change the hours.

25
00:01:33,340 --> 00:01:39,190
That's the downside of copying pasting because it's very easy to make some kind of silly mistake.

26
00:01:39,490 --> 00:01:42,130
So let's first change this one to a response one.

27
00:01:42,460 --> 00:01:44,710
Now, this is not going to be config.

28
00:01:45,280 --> 00:01:46,800
I'm just going to say response.

29
00:01:46,810 --> 00:01:48,460
I believe that's what they have in the docs.

30
00:01:48,700 --> 00:01:50,130
We don't need this line of code.

31
00:01:50,200 --> 00:01:53,920
We're not going to be handing this, which simply want to return the response.

32
00:01:54,220 --> 00:01:54,580
Correct.

33
00:01:54,910 --> 00:01:56,440
Not once this one is in place.

34
00:01:56,740 --> 00:02:03,080
Knowledge deal with error because this is going to be way more interesting as far as the response one.

35
00:02:03,520 --> 00:02:07,930
And first, I want to just log our online response.

36
00:02:08,169 --> 00:02:13,090
And second, I know that there's going to be a status one on the response.

37
00:02:13,630 --> 00:02:16,300
And here's what I want to do on a status.

38
00:02:16,540 --> 00:02:24,510
I want to check if it's for one, then I want to log something in capital case and if not, well, then

39
00:02:24,520 --> 00:02:27,130
we'll just move on and set up the error.

40
00:02:27,850 --> 00:02:34,600
So in here, let's say if error and not a response and the status is equal to that for one.

41
00:02:34,720 --> 00:02:36,250
So that's the one that we're dreading.

42
00:02:36,640 --> 00:02:39,040
Then let's do a massive console.log.

43
00:02:39,400 --> 00:02:44,080
So let's say you're logged online off an error.

44
00:02:44,320 --> 00:02:48,130
And if it's just a typical error, well, then we won't do anything.

45
00:02:48,460 --> 00:02:53,410
And once we have both interceptors in place now, let's take them out for a test drive.

46
00:02:53,950 --> 00:03:01,240
And I think at this point, I can remove those talks like I made my case and let's move this as well

47
00:03:01,750 --> 00:03:07,930
and mine for time being, I think I can comment about the error response in our update user.

48
00:03:08,260 --> 00:03:10,120
I think it's not that useful.

49
00:03:10,450 --> 00:03:13,750
So let me navigate back to my application online.

50
00:03:14,020 --> 00:03:16,120
Let me refresh state is are you?

51
00:03:16,210 --> 00:03:18,040
So of course I have a typo.

52
00:03:18,550 --> 00:03:21,850
I mean, over here it should be state.

53
00:03:21,850 --> 00:03:22,690
Not state.

54
00:03:23,290 --> 00:03:24,670
OK, let's try one more time.

55
00:03:24,670 --> 00:03:25,900
OK, I have the user.

56
00:03:26,290 --> 00:03:26,860
Awesome.

57
00:03:27,010 --> 00:03:30,250
Let's first Senate just so we can see whether everything works.

58
00:03:30,610 --> 00:03:32,410
In this case, I'm going to go with John.

59
00:03:32,770 --> 00:03:34,510
I get back my update user.

60
00:03:34,810 --> 00:03:35,230
OK.

61
00:03:35,800 --> 00:03:37,750
Clearly, see that I'm sending the Barrett token.

62
00:03:38,020 --> 00:03:38,440
Awesome.

63
00:03:38,770 --> 00:03:40,780
Now let's worry about those responses.

64
00:03:41,590 --> 00:03:47,080
So I'm going to go here to a log and here I'm logging the data that I'm getting back.

65
00:03:47,530 --> 00:03:47,950
All right.

66
00:03:48,660 --> 00:03:51,430
And now let me remove the field first.

67
00:03:51,700 --> 00:03:53,050
Let's send it now.

68
00:03:53,050 --> 00:03:57,280
Notice we're just getting back the error response log.

69
00:03:57,310 --> 00:03:57,670
Correct.

70
00:03:57,970 --> 00:04:01,900
So the status is 400, and the message is please provide all values.

71
00:04:02,140 --> 00:04:06,370
And essentially, this is what we'll be setting up here in the alert.

72
00:04:06,940 --> 00:04:07,930
So this is what we'll say.

73
00:04:07,930 --> 00:04:09,880
Please provide of ours again.

74
00:04:10,300 --> 00:04:14,740
It's kind of hard to see with the 400 responses, meaning the please provide all of our sins.

75
00:04:15,040 --> 00:04:18,130
That's what we are doing on the front, and that's why we commented it out.

76
00:04:18,490 --> 00:04:24,220
I know I'm repeating myself, but I thought that it is important to mention that now what's more interesting

77
00:04:24,220 --> 00:04:26,200
for me is what is going to happen.

78
00:04:26,200 --> 00:04:29,200
What do you think if we remove the token?

79
00:04:29,680 --> 00:04:30,850
So how we can do that?

80
00:04:31,120 --> 00:04:35,920
Well, we can either comment this one out here or we can remove it from the state.

81
00:04:36,130 --> 00:04:38,320
I mean, that is really up to you, I think.

82
00:04:38,860 --> 00:04:42,340
I'm just going to come on this one out in the interceptor.

83
00:04:42,550 --> 00:04:44,440
So again, I'm talking about the request one.

84
00:04:44,890 --> 00:04:47,200
And now let's try to make a request.

85
00:04:47,710 --> 00:04:49,210
So let's send it.

86
00:04:49,660 --> 00:04:51,010
And now we have a different one.

87
00:04:51,310 --> 00:04:57,220
Now we have off error, which means that we are not authorized to make these requests.

88
00:04:58,120 --> 00:05:02,230
And this is the entire point why we were setting up those interceptors.

89
00:05:02,290 --> 00:05:09,910
Because again, we want to control what is the our response because we clearly want to keep track of

90
00:05:09,910 --> 00:05:16,510
the error responses and then we want to make decisions based on those responses and what interceptors

91
00:05:16,930 --> 00:05:17,500
in this case.

92
00:05:17,500 --> 00:05:25,990
More specifically, response interceptor allows us to do is to set up one logic for multiple requests.

93
00:05:26,290 --> 00:05:28,630
Again, this is not just for the profile.

94
00:05:29,290 --> 00:05:31,690
San Diego is going to be for ad jump.

95
00:05:31,900 --> 00:05:33,100
All jump start.

96
00:05:33,400 --> 00:05:36,460
So that way we have our code in one place.

97
00:05:37,090 --> 00:05:43,090
And then if that arrow gets triggered, then our response is pretty much going to be the same.

98
00:05:43,930 --> 00:05:49,720
And then that way, if we want to make some changes, we need only change that in one place.

99
00:05:50,080 --> 00:05:57,220
Hopefully, that is clear, and now we can start finally setting up our update user functionality.

