diff options
Diffstat (limited to 'shared/core-utils')
-rw-r--r-- | shared/core-utils/plugins/hooks.ts | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/shared/core-utils/plugins/hooks.ts b/shared/core-utils/plugins/hooks.ts index 92cb5ad68..3784969b5 100644 --- a/shared/core-utils/plugins/hooks.ts +++ b/shared/core-utils/plugins/hooks.ts | |||
@@ -8,15 +8,24 @@ function getHookType (hookName: string) { | |||
8 | return HookType.STATIC | 8 | return HookType.STATIC |
9 | } | 9 | } |
10 | 10 | ||
11 | async function internalRunHook <T> (handler: Function, hookType: HookType, result: T, params: any, onError: (err: Error) => void) { | 11 | async function internalRunHook <T> (options: { |
12 | handler: Function | ||
13 | hookType: HookType | ||
14 | result: T | ||
15 | params: any | ||
16 | onError: (err: Error) => void | ||
17 | }) { | ||
18 | const { handler, hookType, result, params, onError } = options | ||
19 | |||
12 | try { | 20 | try { |
13 | if (hookType === HookType.FILTER) { | 21 | if (hookType === HookType.FILTER) { |
14 | const p = handler(result, params) | 22 | const p = handler(result, params) |
15 | 23 | ||
16 | if (isPromise(p)) result = await p | 24 | const newResult = isPromise(p) |
17 | else result = p | 25 | ? await p |
26 | : p | ||
18 | 27 | ||
19 | return result | 28 | return newResult |
20 | } | 29 | } |
21 | 30 | ||
22 | // Action/static hooks do not have result value | 31 | // Action/static hooks do not have result value |