0

best solution to handle HAPI validation errors?

Spread the love

in my project i written below route code for hapi

So when I don’t pass the firstName it throws error like this

Now, I was trying to handle the above error in catch

So i found the best solution for this using this below code

If the Joi validation fails, it will trigger the failAction and you will be able to handle the error (sending it to log service and/or return a specific message).

It’s a bit hidden in the doc but here is the relevant part

Leave a Reply

Your email address will not be published. Required fields are marked *