Skip to content

Commit d3e0137

Browse files
committed
rename variables
1 parent 965714e commit d3e0137

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

packages/nextjs/src/utils/withSentry.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@ const { parseRequest } = Handlers;
1010
// purely for clarity
1111
type WrappedNextApiHandler = NextApiHandler;
1212

13-
type AugmentedResponse = NextApiResponse & { __sentryTransaction?: Transaction };
13+
export type AugmentedNextApiResponse = NextApiResponse & {
14+
__sentryTransaction?: Transaction;
15+
};
1416

1517
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
16-
export const withSentry = (handler: NextApiHandler): WrappedNextApiHandler => {
18+
export const withSentry = (origHandler: NextApiHandler): WrappedNextApiHandler => {
1719
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
1820
return async (req, res) => {
1921
// first order of business: monkeypatch `res.end()` so that it will wait for us to send events to sentry before it
@@ -69,12 +71,12 @@ export const withSentry = (handler: NextApiHandler): WrappedNextApiHandler => {
6971

7072
// save a link to the transaction on the response, so that even if there's an error (landing us outside of
7173
// the domain), we can still finish it (albeit possibly missing some scope data)
72-
(res as AugmentedResponse).__sentryTransaction = transaction;
74+
(res as AugmentedNextApiResponse).__sentryTransaction = transaction;
7375
}
7476
}
7577

7678
try {
77-
return await handler(req, res); // Call original handler
79+
return await origHandler(req, res); // Call original handler
7880
} catch (e) {
7981
if (currentScope) {
8082
currentScope.addEventProcessor(event => {
@@ -94,12 +96,12 @@ export const withSentry = (handler: NextApiHandler): WrappedNextApiHandler => {
9496
};
9597
};
9698

97-
type ResponseEndMethod = AugmentedResponse['end'];
98-
type WrappedResponseEndMethod = AugmentedResponse['end'];
99+
type ResponseEndMethod = AugmentedNextApiResponse['end'];
100+
type WrappedResponseEndMethod = AugmentedNextApiResponse['end'];
99101

100102
function wrapEndMethod(origEnd: ResponseEndMethod): WrappedResponseEndMethod {
101-
return async function newEnd(this: AugmentedResponse, ...args: unknown[]) {
102103
const transaction = this.__sentryTransaction;
104+
return async function newEnd(this: AugmentedNextApiResponse, ...args: unknown[]) {
103105

104106
if (transaction) {
105107
transaction.setHttpStatus(this.statusCode);

0 commit comments

Comments
 (0)