Skip to content

Commit 35f560d

Browse files
committed
convert wrapped handler to named function in withSentry
1 parent 649568e commit 35f560d

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
@@ -51,7 +51,11 @@ export type AugmentedNextApiResponse = NextApiResponse & {
5151
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
5252
export const withSentry = (origHandler: NextApiHandler): WrappedNextApiHandler => {
5353
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
54-
return async (req, res) => {
54+
const wrappedHandler: WrappedNextApiHandler = async function (
55+
this: WrappedNextApiHandler,
56+
req: NextApiRequest,
57+
res: NextApiResponse,
58+
) {
5559
// first order of business: monkeypatch `res.end()` so that it will wait for us to send events to sentry before it
5660
// fires (if we don't do this, the lambda will close too early and events will be either delayed or lost)
5761
// eslint-disable-next-line @typescript-eslint/unbound-method
@@ -182,6 +186,8 @@ export const withSentry = (origHandler: NextApiHandler): WrappedNextApiHandler =
182186
// a promise here rather than a real result, and it saves us the overhead of an `await` call.)
183187
return boundHandler();
184188
};
189+
190+
return wrappedHandler;
185191
};
186192

187193
type ResponseEndMethod = AugmentedNextApiResponse['end'];

0 commit comments

Comments
 (0)