Closed TheRealThor closed 3 years ago
With your example, when I go to http://localhost:3000/test
here is what I get as a result...
{"statusCode":400,"error":"Bad Request","message":"Validation failed","validation":{"query":{"source":"query","keys":["test_parameter"],"message":"\"test_parameter\" is required"}}}
I am also facing the same problem. This issue started happening after upgrading to v15
I see what went wrong. I was not using the error handler from celebrate. So, the error details were coming to the details Map which was not handled by me. Now, it is fixed.
Could you share a code example please ?
I use a custom error handler in my application, so I handled the celebrate error on it by checking the err object with https://github.com/arb/celebrate#iscelebrateerrorerr and generated a single message from the details Map of the CelebrateError object. Below is an example error handler of the said implementation: `app.use((err, req, res, next) => { if (isCelebrateError(err)) { let message = ''; for (let value of err.details.values()) { message += value.message + '; '; } res.status(400).json({ message }); }
// Other error handler code...
});`
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
node
v16.3.0 -celebrate
15.0.0 -I am using this mini express setup
the error thrown is when no test_parameter is provided is:
How can I find out more about why the validation failed (for example because test_parameter is mandatory)? The "details" key in the error object is empty, which I found out when I used an error handler and had those details printed to console.log.
When I downgrade to celebrate version 13.04 , a detailed error message is provided ("message":"\"test_parameter\" is required)