Skip to content

Commit 5970fed

Browse files
author
Luca Forstner
committed
Rethrow error in withErrorInstumentation
1 parent 06d3a0a commit 5970fed

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

packages/nextjs/src/config/wrappers/wrapperUtils.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,20 @@ export function withErrorInstrumentation<F extends (...args: any[]) => any>(
3535
origFunction: F,
3636
): (...params: Parameters<F>) => ReturnType<F> {
3737
return function (this: unknown, ...origFunctionArguments: Parameters<F>): ReturnType<F> {
38-
const potentialPromiseResult = origFunction.call(this, ...origFunctionArguments);
39-
// We do this instead of await so we do not change the method signature of the passed function from `() => unknown` to `() => Promise<unknown>`
40-
Promise.resolve(potentialPromiseResult).catch(err => {
38+
try {
39+
const potentialPromiseResult = origFunction.call(this, ...origFunctionArguments);
40+
// First of all, we need to capture promise rejections so we have the following check, as well as the try-catch block.
41+
// Additionally, we do the following instead of `await`-ing so we do not change the method signature of the passed function from `() => unknown` to `() => Promise<unknown>.
42+
Promise.resolve(potentialPromiseResult).catch(err => {
43+
// TODO: Extract error logic from `withSentry` in here or create a new wrapper with said logic or something like that.
44+
captureException(err);
45+
});
46+
return potentialPromiseResult;
47+
} catch (e) {
4148
// TODO: Extract error logic from `withSentry` in here or create a new wrapper with said logic or something like that.
42-
captureException(err);
43-
});
44-
return potentialPromiseResult;
49+
captureException(e);
50+
throw e;
51+
}
4552
};
4653
}
4754

0 commit comments

Comments
 (0)