Skip to content

Commit d956a87

Browse files
committed
store captured transaction on response
1 parent d3e0137 commit d956a87

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
@@ -89,6 +90,7 @@ export const withSentry = (origHandler: NextApiHandler): WrappedNextApiHandler =
8990
captureException(e);
9091
}
9192
throw e;
93+
(res as AugmentedNextApiResponse).__sentryCapturedError = e;
9294
}
9395
});
9496

@@ -100,8 +102,8 @@ type ResponseEndMethod = AugmentedNextApiResponse['end'];
100102
type WrappedResponseEndMethod = AugmentedNextApiResponse['end'];
101103

102104
function wrapEndMethod(origEnd: ResponseEndMethod): WrappedResponseEndMethod {
103-
const transaction = this.__sentryTransaction;
104105
return async function newEnd(this: AugmentedNextApiResponse, ...args: unknown[]) {
106+
const { __sentryTransaction: transaction, __sentryCapturedError: capturedError } = this;
105107

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

0 commit comments

Comments
 (0)