arb / celebrate

A joi validation middleware for Express.
MIT License
1.33k stars 66 forks source link

Celebrate 13.x + Joi custom error --> throws AssertionError #197

Closed palazzetti closed 4 years ago

palazzetti commented 4 years ago

My joi schema looks like this:

image image

Here is an example value that is not working as expected:

image

The issue I am having with celebrate is:

After the update to celebrate 13.x, when is time to throw the error from joi i get the above error. From what I understand, the error generated by Joi doesn't like to celebrate. I've already tried using CelebrateError without success. Thanks.

arb commented 4 years ago

You'd want to throw a Joi Validation error in your first screenshot, not a built in Error object. Also, if you're just trying to control the message, check out the .message() API.

monsterooo commented 3 years ago

You'd want to throw a Joi Validation error in your first screenshot, not a built in Error object. Also, if you're just trying to control the message, check out the .message() API.

route.post("/register", celebrate({
    [Segments.BODY]: Joi.object({
      name: Joi.string().$.min(3).max(24).message('error message info'),
    })
  }), async (req, res) => {
    res.json({});
  });

😁