In my previous article, What I’ve Learned Validating with Joi, I detailed general form validation that plays to the strengths of Joi in my latest project. But an area of weakness in the library is one I had set out to tackle since - displaying custom internationalisation (i18n) error messages.

First, there are libraries like Relish that help address this issue but I believed there was a solution without bringing in another library. I set out to rewrite the project’s validation from scratch for two reasons; 1) to simplify logic that was becoming a challenge to scale and 2) gain a deeper understanding of Joi and how it can be used.

So where do you even start? I started with the most minimalist approach that mimicked the project’s current implementation. I wanted to validate one small piece of data to create an error so I could review the raw data returned from Joi.

#javascript

Building Custom & Localised Error Messages with Joi
1.55 GEEK