mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-09 19:22:51 +00:00
fix: make index route work correctly
This commit is contained in:
committed by
Rainer Killinger
parent
24e27c1d9e
commit
fa2c9d7a88
@@ -13,7 +13,7 @@
|
|||||||
* You should have received a copy of the GNU Affero General Public License
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
import {SCConfigFile, SCIndexResponse, SCIndexRoute} from '@openstapps/core';
|
import {SCIndexResponse, SCIndexRoute} from '@openstapps/core';
|
||||||
import {configFile} from '../common';
|
import {configFile} from '../common';
|
||||||
import {createRoute} from './Route';
|
import {createRoute} from './Route';
|
||||||
|
|
||||||
@@ -24,8 +24,10 @@ const indexRouteModel = new SCIndexRoute();
|
|||||||
*/
|
*/
|
||||||
export const indexRouter = createRoute<SCIndexResponse>(
|
export const indexRouter = createRoute<SCIndexResponse>(
|
||||||
indexRouteModel,
|
indexRouteModel,
|
||||||
async (_request: SCIndexRoute, _app) => {
|
async (): Promise<SCIndexResponse> => {
|
||||||
const {internal, ...configObject}: SCConfigFile = configFile;
|
return {
|
||||||
return configObject;
|
app: configFile.app,
|
||||||
|
backend: configFile.backend,
|
||||||
|
};
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ 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';
|
||||||
@@ -71,9 +70,6 @@ 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);
|
||||||
|
|
||||||
@@ -99,13 +95,15 @@ export function createRoute<RETURNTYPE>(
|
|||||||
responseErrors,
|
responseErrors,
|
||||||
isTestEnvironment,
|
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,
|
validationError,
|
||||||
req.app.get('isTestEnvironment'),
|
isTestEnvironment,
|
||||||
);*/
|
);
|
||||||
res.status(validationError.statusCode);
|
res.status(internalServerError.statusCode);
|
||||||
res.json(validationError);
|
res.json(internalServerError);
|
||||||
logger.warn(validationError);
|
logger.warn(internalServerError);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user