Skip to content

Commit d8cf291

Browse files
committed
use local.bind rather than local.run
1 parent 7330344 commit d8cf291

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

packages/nextjs/src/utils/handlers.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ export const withSentry = (handler: NextApiHandler): WrappedNextApiHandler => {
2020
local.add(req);
2121
local.add(res);
2222

23-
local.run(async () => {
23+
// `local.bind` causes everything to run inside a domain, just like `local.run` does, but it also lets the callback
24+
// return a value. In our case, all any of the codepaths return is a promise of `void`, but nextjs still counts on
25+
// getting that before it will finish the response.
26+
const boundHandler = local.bind(async () => {
2427
try {
2528
const currentScope = getCurrentHub().getScope();
2629

@@ -87,5 +90,7 @@ export const withSentry = (handler: NextApiHandler): WrappedNextApiHandler => {
8790
}
8891
}
8992
});
93+
94+
return await boundHandler();
9095
};
9196
};

0 commit comments

Comments
 (0)