1
00:00:06,830 --> 00:00:08,060
Welcome back.

2
00:00:08,090 --> 00:00:10,820
In the previous video, this where we left.

3
00:00:11,150 --> 00:00:17,300
So what we are going to do is we are going to work on reinject value here in case our promise fails.

4
00:00:17,320 --> 00:00:19,400
So for this, I mean code.

5
00:00:19,430 --> 00:00:23,390
Our promise has been failed because here is first is false.

6
00:00:23,390 --> 00:00:29,020
Therefore, this function is not going to be called, but this function is will be called.

7
00:00:29,030 --> 00:00:32,299
So how are we going to handle this use case?

8
00:00:32,299 --> 00:00:33,530
And pretty simple.

9
00:00:36,720 --> 00:00:38,570
Because something churning.

10
00:00:38,610 --> 00:00:44,960
Churning simply means that for one object we can use many methods on that object.

11
00:00:44,970 --> 00:00:48,450
Using Dot you can see that this an object, right?

12
00:00:48,450 --> 00:00:51,180
And first we use those then using Dot here.

13
00:00:51,270 --> 00:00:57,060
So apart from this one where we can also change, use dot and catch.

14
00:00:57,390 --> 00:01:01,650
So we catch is submitted that correspond to reject.

15
00:01:01,650 --> 00:01:06,150
So anything that is inside our reject will be found instead of a catch.

16
00:01:06,150 --> 00:01:11,340
When you call it the same way as a function, then pass in one argument.

17
00:01:11,370 --> 00:01:13,340
I'm going to use arrow function for this.

18
00:01:13,350 --> 00:01:14,600
It can be anything.

19
00:01:14,610 --> 00:01:16,760
It can be a normal function or error function.

20
00:01:16,770 --> 00:01:17,510
Perfect.

21
00:01:17,520 --> 00:01:21,120
So the same way we have the value we pass in to this.

22
00:01:21,120 --> 00:01:23,750
So here, well let's just console.log.

23
00:01:23,760 --> 00:01:25,200
Let's say that

24
00:01:27,510 --> 00:01:31,740
something went wrong.

25
00:01:31,770 --> 00:01:35,550
I believe we see this kind of errors most times in most applications.

26
00:01:35,790 --> 00:01:39,690
So if I save it differently, this function will be called here, right?

27
00:01:39,690 --> 00:01:40,800
So save it.

28
00:01:40,800 --> 00:01:41,660
And let's see.

29
00:01:41,670 --> 00:01:47,460
Indeed, something went wrong, meaning that this function is being called.

30
00:01:47,670 --> 00:01:53,340
But the good thing is that instead of us passing in static text here, we want to pass in the error

31
00:01:53,370 --> 00:01:55,440
coming from the server or database.

32
00:01:55,440 --> 00:02:02,450
For the meantime, let's say that error fetching user.

33
00:02:03,450 --> 00:02:06,960
Try again later.

34
00:02:07,390 --> 00:02:07,710
Okay.

35
00:02:07,710 --> 00:02:09,509
So when I save it now let's see.

36
00:02:09,509 --> 00:02:13,230
Presto, I don't get that error here, which is this error.

37
00:02:13,240 --> 00:02:20,280
But instead I only see the console.log inside this because I'm not making use of this the same way we

38
00:02:20,280 --> 00:02:24,050
pass in an argument to the catch called error.

39
00:02:24,060 --> 00:02:26,310
Most times we use error.

40
00:02:26,520 --> 00:02:27,360
Okay.

41
00:02:27,360 --> 00:02:33,680
So it means that the arguments of this one represent the value in my reject.

42
00:02:33,690 --> 00:02:41,350
So here instead of this one I can now console.log dynamic text here or is my error when I save it now.

43
00:02:41,370 --> 00:02:42,480
Error correction user.

44
00:02:42,480 --> 00:02:44,610
Something went wrong.

45
00:02:44,640 --> 00:02:45,860
That is it.

46
00:02:45,870 --> 00:02:52,380
But if I change this one to true, it means that our promise is resolved.

47
00:02:52,410 --> 00:02:54,980
Therefore I'm going to have my user.

48
00:02:54,990 --> 00:03:00,840
So like I said, that a promise return one value whether I resolve or reject.

49
00:03:01,410 --> 00:03:03,600
So that is all what I have for you.

50
00:03:03,600 --> 00:03:04,740
And I promise.

51
00:03:04,740 --> 00:03:07,020
Well, we haven't finished yet.

52
00:03:07,050 --> 00:03:11,490
Remember, we talk about one key point I said I've explained to you.

53
00:03:11,490 --> 00:03:15,060
So let's come back to the fact about promise.

54
00:03:15,090 --> 00:03:20,370
That is, when returning a promise from a function.

55
00:03:21,220 --> 00:03:25,330
The function returned a performance, but not the actual value of the promise.

56
00:03:25,330 --> 00:03:30,220
And then the value of the promise will be retained when the promise is resolved.

57
00:03:30,220 --> 00:03:30,830
Well.

58
00:03:30,850 --> 00:03:36,250
In this case, we are not making use of any function, just using the promise syntax.

59
00:03:36,520 --> 00:03:43,330
So what we are going to do is that the net result is that we are going to create a function with a promise

60
00:03:43,660 --> 00:03:49,600
and then I'm going to see how we can consume that promise using the function.

61
00:03:49,630 --> 00:03:50,560
All right.

62
00:03:50,890 --> 00:03:54,250
So let's get into that in the next video, guys.

