Closed kdankert closed 4 years ago
I don't really know TypeScript well enough to maintain these myself. If anyone from the community could step up here, I'd sure appreciate it! Failing that, I'll probably just delete them since it's a constant maintenance hassle.
I'm gonna have another look at the file and try to solve this.
I actually was able to solve this issue, I'll open a merge request for this.
How do errors behave right now. Does app.use(errors());
still need to be called?
When I use the following code I receive an 500 internal sever error instead of a 4xx Response. How am I able to set the error code or is this a bug:
router.post("/", celebrate({
body: Joi.object().keys({
data: Joi.array().items(Joi.string())
})
}), async (req: Request, res: Response) => {
const data = Promise.all(req.body.data.map(async (test: any) => await convert(test)));
res.json({data: await data});
});
If you don't use errors()
then the default express error handler will be used which responds with a 500 and an HTML page. In your code, that async
function won't fire because the celebrate
call will call next(err)
and will use the default error handler.
So how do I have to change this code snippet in order to work with the celebrate error handler?
I tried it with app.use(errors()) and without which gives me the same result
Solved this issue by putting app.use(errors())
below the router.
node
version - v13.1.0celebrate
version - 11.0.0-rc3@hapi/joi
version - 16.1.7I got the problem that I cant use celebrate with typescript as it throws an error building the project.
This is probably because of the typing file, unfortunately I don't exactly know how they work, I would have tried to solve this problem myself.