From 4dc83e80981cda5e2ac6569687aad31dae57cc81 Mon Sep 17 00:00:00 2001 From: Agustin Ruiz Diaz <agustin.ruiz.diaz@fing.edu.uy> Date: Thu, 14 Oct 2021 23:18:17 -0300 Subject: [PATCH] ValidationError message fix(should be refactored) --- src/index.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 64303bb..3159ac4 100644 --- a/src/index.ts +++ b/src/index.ts @@ -44,7 +44,13 @@ app.use((error: Error, request: Request, response: Response, next: NextFunction) // Check the error is a validation error if (error instanceof ValidationError) { // TODO: Handle error message accordingly - response.status(400).send(error.validationErrors.body); + let msg: string | undefined; + if (error.validationErrors.body && error.validationErrors.body[0]) { + msg = error.validationErrors.body[0].message; + } + if (msg) { + response.status(400).send(msg); + } next(); } else { // Pass error on if not a validation error -- GitLab