No.
Geez, errors are really, really powerful and I honestly don't see too much of the need to customize
this module itself.
So notice here you can see that there is a new error and you can simply just come up here and raise
the message.
So all you got to do whenever you need to send an error response as a message, just like we have been
saying.
Resident Send you simply go ahead and say.
Resident Send inside that you just come up here and say, Hey, just construct a new error.
That's it.
That's all you got to do.
And you will see that sometimes we'll be sending the error messages when let's just say we didn't find
the user inside our database or something, we'll be sending these messages and it is perfectly 100%
okay to just go ahead and say that, hey, I want to use this default new error message, but I've seen
people actually overcomplicating this stuff.
I'll show you how they do it and how we can keep it actually bare minimum there so that, you know,
okay, I can go ahead and create these customize error messages or customize error handlers as well.
But my recommendation is you shouldn't be doing that, at least not too much.
So let me go ahead and bring it up to you.
So how we're going to be working with that now, this is going to be our very first utility that we
are going to go ahead and.
Right, so open this up new file and let's call this one as simply a custom error.
Jeez.
Of course.
There we go.
Now in here, we want to go ahead and simply create a class what this class is going to be called as.
So we're going to call this one as custom header just to look fancy.
You don't need to create that.
And this obviously is going to go ahead and extend what class.
We're going to extend the classic error class.
So you obviously need to study it a little bit more in case you want to go with that.
And I have seen in some of the application that this is how they work on.
And finally after that, they go ahead and say, hey, module exports and equals errors.
That's it, that's it.
I have seen this class to be totally empty, no functionality, nothing.
But they don't want to use the classic error class.
They want to use own their customer.
So this is kind of a thing that I've seen in many of the production code even as well.
Now further down the road, you can do in case you want to truly customize.
This is by default.
This class actually takes just one thing, which is a message.
Now you can kind of redefine the constructor in this class that instead of calling new error, you call
new customer and it accepts error message error code, probably something more of the definitions that
you want to give it to that so you can go ahead and do that.
All we got to do for that is create another constructor, kind of overriding the existing constructor.
So there constructor the error, just take the message.
So we will take that as well.
We don't want to change that.
And you can go ahead and you can go ahead and say, hey, I want to accept the code as well.
That's it.
And this code is rather a status code.
So just go ahead and provide me that as well.
Further down the road, you're going to go ahead and say, hey, I want to use the functionality which
is built in, so I'll use the super keyword and I'll just pass on the message as it is.
But further down the road, I'm going to go ahead and say, Hey, I'm creating a new property which
is going to be filled up by the code that you are giving to me.
So that's it.
That's basically it.
Now, whenever you want to use this one, this error message, since this is kind of a super or a parent
of this error, this will definitely display as it is how they were displaying the message, but now
they will display the code as well.
That's basically it.
Again, I don't see a point of doing this because already you can you have the option of raising the
status inside.
Whenever you send the request.
You can also go ahead and use this error and message.
But this is like a little bit of an overkill that I see a lot of places that that is exactly why I wanted
to bring this to your attention.
I will show you that how you can use this custom error as well as just the regular error class itself.
And we will be deliberately creating some of these errors and working through with that.
So that's basically it.
That's exactly how you handle customer errors.
And again, there are a lot more properties going up here.
Maybe stack, trace, maybe you want to go with the error code itself.
So this is exactly what we have.
We have got an error code, we have got error message error stack.
There is a whole lot you want to overwrite any of them.
Go ahead, be my guest and do that.
But at least not till the code is finished up.
So this is basically your customized error handling in the Node.js personal recommendation.
You go with the classic error.
Let's go ahead and catch up in the next video.