uzochukwueddie / chatty-backend

96 stars 50 forks source link

Joi schema validation decorator not cascading error found to error middleware #15

Open Ajulibe opened 2 years ago

Ajulibe commented 2 years ago

Hi. I discovered that the joi validator decorator isn't sending the error to the general error middleware. it just throws the error and crashes the server if there is an error in the request object. I think it would be better to use

return next(new JoiRequestValidationError(error.details[0].message))

instead of

throw new JoiRequestValidationError(error.details[0].message)

this way , when we call the next function, the middleware is explicitly told to take the error and respond to it. This fixed my issue.

I have added the picture below to help in locating the problem.

Screenshot 2022-09-19 at 15 48 45
ssoni-gs commented 1 year ago

image

uzoeddie commented 1 year ago

That makes sense. Thank you very much.

kronos202 commented 10 months ago

i had a trouble when i fixed like you. That make unit test of signup function work unexpectedly so i rewrite same as video ( throw new JoiRequestValidationError(error.details[0].message) )