Skip to content

Commit

Permalink
refactor: align before/afterEach function design
Browse files Browse the repository at this point in the history
  • Loading branch information
lhokktyn committed Oct 5, 2024
1 parent 8c7cef6 commit 891e0cb
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions src/dsl/verifier/proxy/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
};

Expand Down

0 comments on commit 891e0cb

Please sign in to comment.