Joi | Validation Error message is printed with unexpcted characters

Viewed 82

We started to use Joi ("version": "17.4.2") for our type validation. I wish to use Joi's error message property and display it to our users but Unfortunately the message is coming back to the user in the following way:

"{\n "password": "mypass123",\n [41m"username"[0m[31m [1]: -- missing --[0m\n}\n[31m\n[1] "username" is required[0m"

expected:

"username" is required

there is not much to see at the code sample: (BadRequestError receiving a string, and working well)

if (isValidationError(error))
{
    return new BadRequestError(error.message);
}

my schema:

    export const workGroupValidationSchema = Joi.object({
    username: Joi.string().required(),
    password: Joi.string().required(),
});

My guess is that for some reason it try to render a message for console and not as a simple string, any ideas?

0 Answers
Related