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

Commit

Permalink
Removed Promise chaining for calling original function after `beforeE…
Browse files Browse the repository at this point in the history
…xecution` hook
  • Loading branch information
Serkan ÖZAL committed Aug 29, 2019
1 parent 82f8a04 commit a442fb9
Showing 1 changed file with 21 additions and 24 deletions.
45 changes: 21 additions & 24 deletions src/ThundraWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,30 +109,27 @@ class ThundraWrapper {

InvocationSupport.setErrorenous(false);

this.executeHook('before-invocation', beforeInvocationData, false)
.then(() => {
this.pluginContext.requestCount += 1;

try {
const result = this.originalFunction.call(
this.originalThis,
this.originalEvent,
this.wrappedContext,
this.wrappedCallback,
);

if (result && result.then !== undefined && typeof result.then === 'function') {
result.then(this.wrappedContext.succeed, this.wrappedContext.fail);
}

return result;
} catch (error) {
this.report(error, null, null);
return error;
}
}).catch((error) => {
ThundraLogger.getInstance().debug(error);
});
this.executeHook('before-invocation', beforeInvocationData, false);

this.pluginContext.requestCount += 1;

try {
const result = this.originalFunction.call(
this.originalThis,
this.originalEvent,
this.wrappedContext,
this.wrappedCallback,
);

if (result && result.then !== undefined && typeof result.then === 'function') {
result.then(this.wrappedContext.succeed, this.wrappedContext.fail);
}

return result;
} catch (error) {
this.report(error, null, null);
throw error;
}
}

async executeHook(hook: any, data: any, reverse: boolean) {
Expand Down

0 comments on commit a442fb9

Please sign in to comment.