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 d368c80
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 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 => {
if (config.beforeEach) 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 All @@ -31,7 +31,7 @@ export const registerAfterHook = (
config: ProxyOptions,
stateSetupPath: string
): void => {
logger.trace("registered 'afterEach' hook");
if (config.afterEach) logger.trace("registered 'afterEach' hook");
app.use(async (req, res, next) => {
if (req.path !== stateSetupPath && config.afterEach) {
logger.debug("executing 'afterEach' hook");
Expand Down

0 comments on commit d368c80

Please sign in to comment.