mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-07 05:52:57 +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,
|
SCRoute,
|
||||||
SCValidationErrorResponse,
|
SCValidationErrorResponse,
|
||||||
} from '@openstapps/core';
|
} from '@openstapps/core';
|
||||||
|
import {Validator} from '@openstapps/core-tools/lib/validate';
|
||||||
import {Application, Router} from 'express';
|
import {Application, Router} from 'express';
|
||||||
import PromiseRouter from 'express-promise-router';
|
import PromiseRouter from 'express-promise-router';
|
||||||
import {ValidationError} from 'jsonschema';
|
import {ValidationError} from 'jsonschema';
|
||||||
@@ -70,6 +71,9 @@ export function createRoute<RETURNTYPE>(
|
|||||||
route[verb](async (req, res) => {
|
route[verb](async (req, res) => {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
// get the core validator from the app
|
||||||
|
const validator: Validator = req.app.get('validator');
|
||||||
|
|
||||||
// validate request
|
// validate request
|
||||||
const requestValidation = validator.validate(req.body, routeClass.requestBodyName);
|
const requestValidation = validator.validate(req.body, routeClass.requestBodyName);
|
||||||
|
|
||||||
@@ -95,13 +99,13 @@ export function createRoute<RETURNTYPE>(
|
|||||||
responseErrors,
|
responseErrors,
|
||||||
isTestEnvironment,
|
isTestEnvironment,
|
||||||
);
|
);
|
||||||
const internalServerError = new SCInternalServerErrorResponse(
|
/*const internalServerError = new SCInternalServerErrorResponse(
|
||||||
validationError,
|
validationError,
|
||||||
isTestEnvironment,
|
req.app.get('isTestEnvironment'),
|
||||||
);
|
);*/
|
||||||
res.status(internalServerError.statusCode);
|
res.status(validationError.statusCode);
|
||||||
res.json(internalServerError);
|
res.json(validationError);
|
||||||
logger.warn(internalServerError);
|
logger.warn(validationError);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user