Welcome back.
In the previous video, this where we left.
So what we are going to do is we are going to work on reinject value here in case our promise fails.
So for this, I mean code.
Our promise has been failed because here is first is false.
Therefore, this function is not going to be called, but this function is will be called.
So how are we going to handle this use case?
And pretty simple.
Because something churning.
Churning simply means that for one object we can use many methods on that object.
Using Dot you can see that this an object, right?
And first we use those then using Dot here.
So apart from this one where we can also change, use dot and catch.
So we catch is submitted that correspond to reject.
So anything that is inside our reject will be found instead of a catch.
When you call it the same way as a function, then pass in one argument.
I'm going to use arrow function for this.
It can be anything.
It can be a normal function or error function.
Perfect.
So the same way we have the value we pass in to this.
So here, well let's just console.log.
Let's say that
something went wrong.
I believe we see this kind of errors most times in most applications.
So if I save it differently, this function will be called here, right?
So save it.
And let's see.
Indeed, something went wrong, meaning that this function is being called.
But the good thing is that instead of us passing in static text here, we want to pass in the error
coming from the server or database.
For the meantime, let's say that error fetching user.
Try again later.
Okay.
So when I save it now let's see.
Presto, I don't get that error here, which is this error.
But instead I only see the console.log inside this because I'm not making use of this the same way we
pass in an argument to the catch called error.
Most times we use error.
Okay.
So it means that the arguments of this one represent the value in my reject.
So here instead of this one I can now console.log dynamic text here or is my error when I save it now.
Error correction user.
Something went wrong.
That is it.
But if I change this one to true, it means that our promise is resolved.
Therefore I'm going to have my user.
So like I said, that a promise return one value whether I resolve or reject.
So that is all what I have for you.
And I promise.
Well, we haven't finished yet.
Remember, we talk about one key point I said I've explained to you.
So let's come back to the fact about promise.
That is, when returning a promise from a function.
The function returned a performance, but not the actual value of the promise.
And then the value of the promise will be retained when the promise is resolved.
Well.
In this case, we are not making use of any function, just using the promise syntax.
So what we are going to do is that the net result is that we are going to create a function with a promise
and then I'm going to see how we can consume that promise using the function.
All right.
So let's get into that in the next video, guys.