All right, and once our aramid lawyer is able to handle our database errors.
Now let's take a look at how we can check for both errors in the controller as well.
And I'm talking about the registered controller, of course.
First, it will make our API less error prone and second, in some cases checking for specific error
in the controller before it hits the error middleware.
It's actually quite useful, and it's my personal preference to use my error checking in the controller
somewhat irregularly.
Lastly, in the process, we'll also take a look at how we can set up custom or class.
So.
Let's get cracking by first navigating back to the off controller, and let's try to remember where
the values are located, so they're located in the body, correct?
So here's what I can do.
I can just check for name in Maryland passport so I can pull them out.
So name, email, comma and password and now set that one equal to a right down body.
So we pull out the values and all we can do.
We're going to check for empty values.
I'm going to just say here your name is not provided or if email is not provided or if the password
is not private.
Correct.
So if one of them is missing, what can we do?
Well, remember, since we're using the package, the express async arrest package, instead of going
next and passing in some kind of error when we need to do is go through new and for time being.
We'll just rely on JavaScript error class.
And again, if you're on a double check that just go back to the read me and let's click over here,
let's navigate to their index.
And once you get there as a refresher, remember, instead of going with next, we need to go through
an error online.
We pass in the error message.
And this is coming from the JavaScript, and I'll probably mention that 20000 times in the following
video.
So we go with more and let's pass the message.
Let's say please provide on values like show one.
It also kind of makes sense that if we change the sound correct where instead of just passing it, everything
that we're getting from that body, I'll specifically say that I want to pass a name, email and password.
Mike, so let's save it.
And before we can go any further, where we also need to do is go to the arrow handler.
And now let's log specifically the message property.
Because I want to showcase something, so instead of logging the entire object, I'm going to go with
error and message.
Now if you're wondering, how do I know that such message property exists?
Oh, because we're using built in JavaScript error constructor.
And if we take a look at the Indian ducks, we can say that it accepts a message as an argument.
And just to demonstrate that I created a straight up vanilla jazz code where I create an object by invoking
the Arrow Constructor and I passing the message.
And once I logged erudite message, I get back the same value.
Now, if you're wondering, which extension am I using to showcase the results straight up in my text
that are the extension that is cue awkward.
Yes?
Now you don't have to buy a paid version.
Essentially, there is a free version and a paid one.
And as far as my use cases, I find the free version to be sufficient enough.
So now let's head back to the postman and again, once remove the name, that probably is going to be
the easiest.
So let's send it here, and I'm getting back to five hundred and I still have something went wrong,
so I do have the generic one.
But let's take a look at the console and console over here says please provide all the values.
Now, where is this coming from from here?
Because this is the message that repression.
So the first thing that we can do in order to set this up as 400 and then the actual message that we're
passing in is in the era handler by setting up here the operator.
So like I said in the beginning, it kind of looked useless, correct?
Setting up this object, the default error.
However, as we're adding more code, this looks very useful, correct?
And now what I can do is say OK, if in the error that is being passed to this middleware, if there
is already a message, then use that one.
However.
If there isn't one, then just go generic one.
So the way that's going to look like we're going to go with air again, this is this error over here.
Van, let's go with that message.
And if it's present, then we'll go here.
And if not, then we'll just go generic one.
And remember, when it comes to the Mongols ones, we're overriding that anyway.
So don't think about it too much.
So let's go back over here.
Let's Senate.
And what?
I still have five hundred fix that one in the following video, but not least, our message is custom.
And what we're doing right now in the controller, we're actually checking for devices ourselves, which
are going from time to time can be very useful.