Skip to content

Commit 538cf2f

Browse files
committed
convert wrapped handler to named function in withSentry
1 parent f7a4846 commit 538cf2f

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

packages/nextjs/src/utils/withSentry.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,11 @@ export type AugmentedNextApiResponse = NextApiResponse & {
4848
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
4949
export const withSentry = (origHandler: NextApiHandler): WrappedNextApiHandler => {
5050
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
51-
return async (req, res) => {
51+
const wrappedHandler: WrappedNextApiHandler = async function (
52+
this: WrappedNextApiHandler,
53+
req: NextApiRequest,
54+
res: NextApiResponse,
55+
) {
5256
// first order of business: monkeypatch `res.end()` so that it will wait for us to send events to sentry before it
5357
// fires (if we don't do this, the lambda will close too early and events will be either delayed or lost)
5458
// eslint-disable-next-line @typescript-eslint/unbound-method
@@ -183,6 +187,8 @@ export const withSentry = (origHandler: NextApiHandler): WrappedNextApiHandler =
183187
// Flag the original handler as already having been wrapped, to prevent it from being wrapped twice (which it could
184188
// be, if someone has already wrapped it manually and then we come along and auto-wrap it)
185189
wrappedHandler.__sentry_wrapped__ = true;
190+
191+
return wrappedHandler;
186192
};
187193

188194
type ResponseEndMethod = AugmentedNextApiResponse['end'];

0 commit comments

Comments
 (0)