From fa2c9d7a881d9e94da8512349056b69206e4e3d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wieland=20Sch=C3=B6bl?= Date: Tue, 2 Apr 2019 11:25:10 +0200 Subject: [PATCH] fix: make index route work correctly --- src/routes/IndexRoute.ts | 10 ++++++---- src/routes/Route.ts | 18 ++++++++---------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/routes/IndexRoute.ts b/src/routes/IndexRoute.ts index 85a88dd5..9c460040 100644 --- a/src/routes/IndexRoute.ts +++ b/src/routes/IndexRoute.ts @@ -13,7 +13,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -import {SCConfigFile, SCIndexResponse, SCIndexRoute} from '@openstapps/core'; +import {SCIndexResponse, SCIndexRoute} from '@openstapps/core'; import {configFile} from '../common'; import {createRoute} from './Route'; @@ -24,8 +24,10 @@ const indexRouteModel = new SCIndexRoute(); */ export const indexRouter = createRoute( indexRouteModel, - async (_request: SCIndexRoute, _app) => { - const {internal, ...configObject}: SCConfigFile = configFile; - return configObject; + async (): Promise => { + return { + app: configFile.app, + backend: configFile.backend, + }; }, ); diff --git a/src/routes/Route.ts b/src/routes/Route.ts index a12a94e7..42044c85 100644 --- a/src/routes/Route.ts +++ b/src/routes/Route.ts @@ -19,7 +19,6 @@ 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'; @@ -71,9 +70,6 @@ export function createRoute( 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); @@ -99,13 +95,15 @@ export function createRoute( responseErrors, isTestEnvironment, ); - /*const internalServerError = new SCInternalServerErrorResponse( + // The validation error is not caused by faulty user input, but through an error that originates somewhere in + // the backend, therefor we use this "stacked" error. + const internalServerError = new SCInternalServerErrorResponse( validationError, - req.app.get('isTestEnvironment'), - );*/ - res.status(validationError.statusCode); - res.json(validationError); - logger.warn(validationError); + isTestEnvironment, + ); + res.status(internalServerError.statusCode); + res.json(internalServerError); + logger.warn(internalServerError); return; }