Currently I have a t.Number field.
When I call t.validate() on it, it gives me the following result.errors:
{
"actual": "James King",
"message": "Invalid value \"James King\" supplied to /user_id: Number",
"path": ["user_id"]
}
Is it possible to modify the output of the t.Number validation to have:
{
"actual": "James King",
"message": "Oops! The value is invalid",
"path": ["user_id"]
}
Also, am I getting that results.errors because I am in NODE_ENV "development"? If so, what results.errors will I get if I am in "production"?
I figured it out in the end.
As per: https://github.com/gcanti/tcomb-validation#customise-error-messages
Attach a getValidationErrorMessage() function to the 'type'. i.e.
Then made the call to tcomb-validate's validate():
const result = t.validate('s', Number);It gave the result with the customized error message: