1
00:00:06,320 --> 00:00:07,610
Welcome back.

2
00:00:07,640 --> 00:00:11,300
Let's continue on the implementation of a promise.

3
00:00:11,480 --> 00:00:17,990
So in this video, we are going to talk about a concept called resolving.

4
00:00:18,470 --> 00:00:20,570
You're going to hear this name a lot.

5
00:00:20,600 --> 00:00:28,460
Resolving simply means that getting the response from a function, meaning that resolving it can be

6
00:00:28,460 --> 00:00:33,100
error or success, meaning gets what is coming back from a promise.

7
00:00:33,110 --> 00:00:36,380
So how can we make this of resolving?

8
00:00:36,410 --> 00:00:40,490
Well, remember this entire function here.

9
00:00:41,480 --> 00:00:44,150
The value would be assigned into promise.

10
00:00:44,150 --> 00:00:51,710
So let's try to console.log promise and let's see what we have inside the promise that we have created.

11
00:00:51,710 --> 00:00:57,080
So if I check it, you will see that I have fulfilled and then undefined.

12
00:00:57,080 --> 00:00:57,650
Perfect.

13
00:00:57,650 --> 00:01:04,760
So let's go ahead and then I mean, read more code to get an actual value because what we want is these

14
00:01:04,760 --> 00:01:05,450
values.

15
00:01:05,450 --> 00:01:06,830
That is my user.

16
00:01:07,040 --> 00:01:09,050
Okay, not this.

17
00:01:09,050 --> 00:01:11,750
I mean, for what you see here.

18
00:01:12,170 --> 00:01:14,300
Okay, so how are we going to do it?

19
00:01:14,300 --> 00:01:17,030
So now let's remove this one again.

20
00:01:17,030 --> 00:01:19,730
This name can be anything perfect.

21
00:01:19,730 --> 00:01:21,980
It can be my promise or user promise.

22
00:01:21,980 --> 00:01:29,090
But think because this promise is fetching user, we can make it as user promise to be more specific.

23
00:01:30,260 --> 00:01:32,000
User promise.

24
00:01:32,000 --> 00:01:32,600
Perfect.

25
00:01:32,600 --> 00:01:34,730
So now I have my user promise here.

26
00:01:34,730 --> 00:01:37,100
So how can I get what I want?

27
00:01:37,100 --> 00:01:39,830
So here we go on the promise.

28
00:01:39,830 --> 00:01:50,420
We have two method core then and catch well we use then to get a value when a promise is resolved.

29
00:01:50,660 --> 00:01:56,420
So here I'll make use of dot then as a function call.

30
00:01:57,080 --> 00:02:03,410
So the then is used or is a function that gets a value from resolve here.

31
00:02:04,440 --> 00:02:11,450
So remember the then also takes in one argument that is callback so here pass in a callback function.

32
00:02:11,460 --> 00:02:15,120
It can be a function or a normal function.

33
00:02:15,180 --> 00:02:17,400
Let me use normal function here this time around.

34
00:02:17,400 --> 00:02:19,110
And here we go.

35
00:02:19,740 --> 00:02:20,220
Perfect.

36
00:02:20,220 --> 00:02:23,190
And again inside the callback of Dot.

37
00:02:23,220 --> 00:02:30,300
Then for this callback I'm going to pass in one argument and I'll show you in just a second.

38
00:02:30,510 --> 00:02:36,630
So inside the body here, how can we get the values for the resolve?

39
00:02:36,900 --> 00:02:55,950
So let me say that dot, dot, then dot then is as a function is used to get the value from resolve

40
00:02:55,980 --> 00:03:03,980
function in my premise in the resolve resolve function from promise.

41
00:03:03,990 --> 00:03:04,620
Yes.

42
00:03:04,620 --> 00:03:13,590
So here, one cool thing about resolve is that we can now pass anything that we want the user to see.

43
00:03:13,830 --> 00:03:16,530
So let's say that for the meantime, let's pass in.

44
00:03:16,740 --> 00:03:21,570
Yes, it is resolved.

45
00:03:22,170 --> 00:03:22,710
Good.

46
00:03:22,710 --> 00:03:29,760
So coming down here, if I serve this function, check my console, nothing being displayed.

47
00:03:30,060 --> 00:03:34,590
I can go ahead and say just display anything.

48
00:03:34,590 --> 00:03:38,550
Let's say that any value here.

49
00:03:39,570 --> 00:03:43,170
So when I save it, it will see that I have any value.

50
00:03:43,170 --> 00:03:48,210
But what we want is the response coming back from my promise.

51
00:03:48,360 --> 00:03:49,410
That is the result.

52
00:03:49,410 --> 00:03:57,450
So it means that anything we pass in as an argument to resolve, we can get it inside our callback function

53
00:03:57,450 --> 00:04:01,260
by providing an argument to the callback function of those.

54
00:04:01,260 --> 00:04:06,060
Then so here it can be anything, it can be data, it can be value.

55
00:04:06,090 --> 00:04:07,530
The choice is yours.

56
00:04:08,010 --> 00:04:14,160
So here this value now represents what is inside my resolve function here.

57
00:04:14,580 --> 00:04:21,959
So instead of this one, I cannot console.log the value or response from my result.

58
00:04:21,959 --> 00:04:29,400
Let's say that value from resolve maybe to be more specific here.

59
00:04:31,570 --> 00:04:32,170
Resolved.

60
00:04:32,170 --> 00:04:36,670
So here I cannot console the value and let's see if indeed we have it.

61
00:04:36,670 --> 00:04:38,990
And now yes, it is resolved.

62
00:04:39,040 --> 00:04:43,960
This test or response is coming from this function down here.

63
00:04:44,380 --> 00:04:44,690
Sorry.

64
00:04:44,740 --> 00:04:45,370
Up here.

65
00:04:46,000 --> 00:04:49,780
So instead of just returning this test, we won't get the user.

66
00:04:49,780 --> 00:04:54,940
So I cannot pass this user to my resolve as user.

67
00:04:55,210 --> 00:04:58,480
So if I save it, what are you going to see in a console?

68
00:04:58,520 --> 00:05:03,490
You are going to see what the user object because what we pass in to this function.

69
00:05:03,490 --> 00:05:10,900
So here we have this user inside my callback, then I just console.log down here a let's check it out.

70
00:05:10,900 --> 00:05:15,850
So when I say it nine you see that I have my user object.

71
00:05:15,970 --> 00:05:21,940
The function is resolved because there is all function is being called but not this.

72
00:05:21,940 --> 00:05:27,010
And again, because this condition is true, that is why this function is being called.

73
00:05:27,250 --> 00:05:30,730
But let's change this one to force when I save it.

74
00:05:30,760 --> 00:05:31,960
What's going to happen?

75
00:05:32,290 --> 00:05:35,230
Is this function going to be called or this one?

76
00:05:35,800 --> 00:05:39,130
Think about it perfect because it's force.

77
00:05:39,130 --> 00:05:40,420
This condition is false.

78
00:05:40,420 --> 00:05:42,340
Therefore this one will be called.

79
00:05:42,340 --> 00:05:44,170
So when I save it.

80
00:05:44,380 --> 00:05:45,640
Now, check it out.

81
00:05:46,120 --> 00:05:50,290
You see, we have beautiful error called on cuts in promise.

82
00:05:50,650 --> 00:05:53,230
This is the kind of error we are going to see.

83
00:05:53,230 --> 00:05:55,150
A lot, a lot, a lot.

84
00:05:55,810 --> 00:06:04,600
Okay, so this error simply means that we are making of promise, but we are not handling the error

85
00:06:04,600 --> 00:06:07,810
case in case the promise reject or failed.

86
00:06:07,840 --> 00:06:14,500
How are we going to display or get the actual error and send to the user because we are not handling

87
00:06:14,500 --> 00:06:15,700
that error here.

88
00:06:15,730 --> 00:06:20,750
That's why JavaScript by default gives us this error in time you see in promise.

89
00:06:20,770 --> 00:06:27,460
It means that there is something going wrong in your code that is the rejected or your premise is being

90
00:06:27,460 --> 00:06:28,000
failed.

91
00:06:28,000 --> 00:06:30,630
But we are not catching it or using it.

92
00:06:30,640 --> 00:06:34,720
So how are you going to make use of this reject and display?

93
00:06:34,720 --> 00:06:39,490
A beautiful error says that error fetching user or network error.

94
00:06:39,520 --> 00:06:40,150
All right.

95
00:06:40,150 --> 00:06:42,760
So let's get into that in the next video guide.

