diff --git a/src/dsl/verifier/proxy/hooks.ts b/src/dsl/verifier/proxy/hooks.ts index dd4a1024c..18bd60a3f 100644 --- a/src/dsl/verifier/proxy/hooks.ts +++ b/src/dsl/verifier/proxy/hooks.ts @@ -8,21 +8,21 @@ export const registerBeforeHook = ( config: ProxyOptions, stateSetupPath: string ): void => { + logger.trace("registered 'beforeEach' hook"); app.use(async (req, res, next) => { - if (config.beforeEach !== undefined) { - logger.trace("registered 'beforeEach' hook"); - if (req.path === stateSetupPath) { - logger.debug("executing 'beforeEach' hook"); - try { - await config.beforeEach(); - } catch (e) { - logger.error(`error executing 'beforeEach' hook: ${e.message}`); - logger.debug(`Stack trace was: ${e.stack}`); - next(new Error(`error executing 'beforeEach' hook: ${e.message}`)); - } + if (req.path === stateSetupPath && config.beforeEach) { + logger.debug("executing 'beforeEach' hook"); + try { + await config.beforeEach(); + next(); + } catch (e) { + logger.error(`error executing 'beforeEach' hook: ${e.message}`); + logger.debug(`Stack trace was: ${e.stack}`); + next(new Error(`error executing 'beforeEach' hook: ${e.message}`)); } + } else { + next(); } - next(); }); };