A
A
Anastasia Egorova2020-11-13 11:35:32
Express.js
Anastasia Egorova, 2020-11-13 11:35:32

How to change custom error celebrate?

doing validation

router.post('/signin', celebrate({
  body: Joi.object().keys({
    email: Joi.string().required().email(),
    password: Joi.string().required()
  })
}), login);

if the email is invalid, an error occurs
{"statusCode":400,"error":"Bad Request","message":"celebrate request validation failed","validation":{"body":{"source":"body","keys":["email"],"message":"\"email\" must be a valid email"}}}

I was looking on the Internet for a way to change to my error, I found one article https://stackoverflow.com/questions/55954369/how-t...
they write that you can change the error in this way
[Segments.BODY]: Joi.object().keys({
value: Joi.string().required().error(new Error('Value is required and has to be a text!')),
})

but I can't. The answer comes like this
{"generatedMessage":false,"code":"ERR_ASSERTION","actual":false,"expected":true,"operator":"=="}

Who is well versed in express, tell me how can I change the celebrate custom error to my own? I will be very grateful to you)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Yarkov, 2020-11-13
@RachelGreen

It?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question