mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2025-12-16 11:16:20 +00:00
fix: return validation error instead of internal server error
previously there was just a validation error inside an internal server error, which made no sense
This commit is contained in:
committed by
Rainer Killinger
parent
59e4009c5d
commit
24e27c1d9e
@@ -19,6 +19,7 @@ import {
|
||||
SCRoute,
|
||||
SCValidationErrorResponse,
|
||||
} from '@openstapps/core';
|
||||
import {Validator} from '@openstapps/core-tools/lib/validate';
|
||||
import {Application, Router} from 'express';
|
||||
import PromiseRouter from 'express-promise-router';
|
||||
import {ValidationError} from 'jsonschema';
|
||||
@@ -70,6 +71,9 @@ export function createRoute<RETURNTYPE>(
|
||||
route[verb](async (req, res) => {
|
||||
|
||||
try {
|
||||
// get the core validator from the app
|
||||
const validator: Validator = req.app.get('validator');
|
||||
|
||||
// validate request
|
||||
const requestValidation = validator.validate(req.body, routeClass.requestBodyName);
|
||||
|
||||
@@ -95,13 +99,13 @@ export function createRoute<RETURNTYPE>(
|
||||
responseErrors,
|
||||
isTestEnvironment,
|
||||
);
|
||||
const internalServerError = new SCInternalServerErrorResponse(
|
||||
/*const internalServerError = new SCInternalServerErrorResponse(
|
||||
validationError,
|
||||
isTestEnvironment,
|
||||
);
|
||||
res.status(internalServerError.statusCode);
|
||||
res.json(internalServerError);
|
||||
logger.warn(internalServerError);
|
||||
req.app.get('isTestEnvironment'),
|
||||
);*/
|
||||
res.status(validationError.statusCode);
|
||||
res.json(validationError);
|
||||
logger.warn(validationError);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user