Skip to content

Commit 15cb042

Browse files
committed
store captured transaction on response
1 parent 780a6bb commit 15cb042

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

packages/nextjs/src/utils/withSentry.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ type WrappedNextApiHandler = NextApiHandler;
1212

1313
export type AugmentedNextApiResponse = NextApiResponse & {
1414
__sentryTransaction?: Transaction;
15+
__sentryCapturedError?: unknown;
1516
};
1617

1718
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
@@ -88,6 +89,7 @@ export const withSentry = (origHandler: NextApiHandler): WrappedNextApiHandler =
8889
captureException(e);
8990
}
9091
throw e;
92+
(res as AugmentedNextApiResponse).__sentryCapturedError = e;
9193
}
9294
});
9395

@@ -99,8 +101,8 @@ type ResponseEndMethod = AugmentedNextApiResponse['end'];
99101
type WrappedResponseEndMethod = AugmentedNextApiResponse['end'];
100102

101103
function wrapEndMethod(origEnd: ResponseEndMethod): WrappedResponseEndMethod {
102-
const transaction = this.__sentryTransaction;
103104
return async function newEnd(this: AugmentedNextApiResponse, ...args: unknown[]) {
105+
const { __sentryTransaction: transaction, __sentryCapturedError: capturedError } = this;
104106

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

0 commit comments

Comments
 (0)