Better error messages for Hapi.js Joi validation
Introduction
Joi provides awesome schema validation, but the error messages returned are not user-friendly. This package returns a more user-friendly version of Joi's default response and allows for custom error messages.
Default Joi Response
Example Relish Response
Installation
npm install relish --save
Usage
First load and initialize the module
// load the package and set custom message optionsconst Relish = messages: 'data.name': 'Please enter your full name' ;
Once initialized, this package exposes a custom failAction
handler that can be used in your Hapi.js Route Options.
// call the failAction handler in your route optionsserver;
Global Usage (alternative)
You can apply this module to all routes by setting the failAction in your server options.
Hapi;
Version Compatibility
Below are the compatible versions of Relish for Hapi and Joi.
Relish Version | Hapi Version | Joi Version |
---|---|---|
1.x | <= 16.6.0 | <= 10.x |
2.x | >= 16.6.1, < 17.x | >= 11.x |
3.x | >= 17.x | >= 11.x |
API Documentation
See the API Documentation for reference.