Skip to content

Commit 0bb0092

Browse files
authored
fix(serverless): Check for existence of callback in GCP event handler before calling (#5608)
1 parent 4670c9f commit 0bb0092

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

packages/serverless/src/gcpfunction/events.ts

+9-5
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,17 @@ export function wrapEventFunction(
2121
}
2222

2323
/** */
24-
function _wrapEventFunction(
25-
fn: EventFunction | EventFunctionWithCallback,
24+
function _wrapEventFunction<F extends EventFunction | EventFunctionWithCallback>(
25+
fn: F,
2626
wrapOptions: Partial<EventFunctionWrapperOptions> = {},
27-
): EventFunctionWithCallback {
27+
): (...args: Parameters<F>) => ReturnType<F> | Promise<void> {
2828
const options: EventFunctionWrapperOptions = {
2929
flushTimeout: 2000,
3030
...wrapOptions,
3131
};
32-
return (data, context, callback) => {
32+
return (...eventFunctionArguments: Parameters<F>): ReturnType<F> | Promise<void> => {
33+
const [data, context, callback] = eventFunctionArguments;
34+
3335
const hub = getCurrentHub();
3436

3537
const transaction = hub.startTransaction({
@@ -62,7 +64,9 @@ function _wrapEventFunction(
6264
__DEBUG_BUILD__ && logger.error(e);
6365
})
6466
.then(() => {
65-
callback(...args);
67+
if (typeof callback === 'function') {
68+
callback(...args);
69+
}
6670
});
6771
});
6872

0 commit comments

Comments
 (0)