Skip to content
Snippets Groups Projects
Commit 207ca65f authored by Ignacio Bengoa Nion's avatar Ignacio Bengoa Nion
Browse files

Validation error handling - Changed from 500 to 400

parent d4fbbdaa
No related branches found
No related tags found
No related merge requests found
/* eslint-disable no-console */
import express, { Application } from 'express';
import { ValidationError } from 'express-json-validator-middleware';
import express, {
Application,
NextFunction,
Request,
Response,
} from 'express';
import 'dotenv/config';
import cors from 'cors';
import swaggerUi from 'swagger-ui-express';
......@@ -34,6 +40,18 @@ app.use(express.raw({
app.use(Routes);
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);
next();
} else {
// Pass error on if not a validation error
next(error);
}
});
ParameterDataBaseLoader.initParameterDataBase();
app.listen(PORT, (): void => {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment