All right let's start to build out this additional functionality inside of our area handling middleware.
So to get started I'm going to find my error handling middleware inside the middleware as directory.
It is right here at the very top.
I'm going to import those two custom air subclasses we just put together once again rather than writing
these out to actually let's just do a copy paste from these sign up root handler.
We're just working on the here sign up dot.
Yes we want these to exact import statements.
So I got a copy both them and then paste them inside of the air handler.
So now at the very top I'm going to delete that console log and we'll add in our little tight checks.
So we're going to say if air is an instance of request validation error then for right now let's just
do a console log and say something like handling this error as a request validation error.
We will also do a return.
Actually we'll leave that return off for just a second.
Let's just make sure we can get these instance of checks work appropriately after that we'll say if
there is an instance of database connection error we'll do a console log of handling this error as a
DV connection error
we'll save this and then let's go ahead and do a quick test over with post man.
So all we're trying to do right now is to make sure that we can interpret the type of that incoming
error so we can eventually handle it appropriately.
So either we'll take the reasons property and send it back.
We'll take that reason property and send it over whatever is most appropriate.
We still need to figure that part out but to test this out we got to open up.
Once again I'll try to handle the invalid request validate or the request a validation error first.
It's going to put in an invalid e-mail and then send this off.
So I've got a status 400 I don't have a message or I've an empty string right there which is no Cape
right now.
More importantly let's go back over to our terminal and take a look at what was console logged out.
So at my terminal I'll see handling this area as request validation error.
Awesome.
So that means that we can tell our error handling middleware how to run some custom logic depending
upon the type of error that it is receiving.
Now let's do a similar test and make sure that it can recognize a database connection error coming in
I'm going to put in a valid e-mail now send it I'll go back over to my terminal again and I see handling
this area as a db connection error.
Awesome.
Ok so now that our error handling middleware can determine what kind of error this is we can add some
code inside there to take off either that reasons property or the reason property in the case of database
connection error and then build up some kind of response and send it back over to the user.
So let's take care of that last step in just a moment.