Skip to content
This repository has been archived by the owner on Jan 12, 2023. It is now read-only.

Commit

Permalink
Fix injections
Browse files Browse the repository at this point in the history
  • Loading branch information
afonsof committed Dec 5, 2019
1 parent 32a0188 commit ca0b04e
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions app-factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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`, ''));
}
};

Expand Down Expand Up @@ -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());
Expand Down

0 comments on commit ca0b04e

Please sign in to comment.