From ca0b04e09997d95a9bee81d3a5bb60103c59e242 Mon Sep 17 00:00:00 2001 From: Afonso F Date: Thu, 5 Dec 2019 16:01:42 -0300 Subject: [PATCH] Fix injections --- app-factory.js | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/app-factory.js b/app-factory.js index 196304d..af3608e 100644 --- a/app-factory.js +++ b/app-factory.js @@ -6,8 +6,6 @@ const elasticApmNode = require('elastic-apm-node'); const { ResponseJsonMiddleware } = require('./middlewares/response-json-middleware'); -let UnexpectedError; - const verifyIntegrityErrors = ({ integrityCheckers }) => { const errors = integrityCheckers.map((checker) => { try { @@ -18,8 +16,8 @@ const verifyIntegrityErrors = ({ integrityCheckers }) => { } }).filter(error => error); if (errors.length) { - throw new UnexpectedError(errors - .reduce((acc, error) => `${acc || ''}${error.message}\n`)); + throw new Error(errors + .reduce((acc, error) => `${acc || ''}${error.message}\n`, '')); } }; @@ -64,17 +62,16 @@ const setupElasticApm = ({ logger, elasticApmEnabled }) => { } }; -module.exports.createApp = ({ integrityCheckers }) => { - verifyIntegrityErrors({ integrityCheckers }); +module.exports.createApp = () => { return restify.createServer(); }; module.exports.injectMiddlewaresAndListen = async ({ app, isSentryEnabled, isDevelopment, isLogRequestEnabled, logger, raven, closeSequelize, port, env, appRoot, swaggerFile, isElasticApmEnabled, isNewRelicApmEnabled, - requestTraceMiddleware, prometheusMiddleware, auditTrailMiddleware, unexpectedError, + requestTraceMiddleware, prometheusMiddleware, auditTrailMiddleware, integrityCheckers = [], }) => { - UnexpectedError = unexpectedError; + verifyIntegrityErrors({ integrityCheckers }); if (isSentryEnabled) { app.use(raven.requestHandler());