feat: use config for MultiSearchRoute

This commit is contained in:
Wieland Schöbl
2019-02-13 17:10:47 +01:00
committed by Rainer Killinger
parent 2b894bd1b6
commit 827827905b
6 changed files with 254 additions and 143 deletions

View File

@@ -22,6 +22,7 @@ import {
import {Validator} from '@openstapps/core-tools/lib/validate';
import {Application, Router} from 'express';
import PromiseRouter from 'express-promise-router';
import {ValidationError} from 'jsonschema';
import {logger} from '../common';
import {isHttpMethod} from './HTTPTypes';
@@ -91,11 +92,11 @@ export function createRoute<RETURNTYPE>(
const response = await handler(req.body, req.app, req.params);
// validate response generated by handler
const responseValidation = validator.validate(response, routeClass.responseBodyName);
const responseErrors: ValidationError[] = validator.validate(response, routeClass.responseBodyName).errors;
if (responseValidation.errors.length > 0) {
if (responseErrors.length > 0) {
const validationError = new SCValidationErrorResponse(
responseValidation.errors,
responseErrors,
req.app.get('isProductiveEnvironment'),
);
const internalServerError = new SCInternalServerErrorResponse(
@@ -115,7 +116,7 @@ export function createRoute<RETURNTYPE>(
res.json(response);
} catch (error) {
// if the error response is allowed on the route
if (routeClass.errorNames.indexOf(error.constructor.name) > -1) {
if (routeClass.errorNames.some((constructorType) => error instanceof constructorType)) {
// respond with the error from the handler
res.status(error.statusCode);
res.json(error);