File tree Expand file tree Collapse file tree 2 files changed +32
-6
lines changed Expand file tree Collapse file tree 2 files changed +32
-6
lines changed Original file line number Diff line number Diff line change @@ -4,15 +4,28 @@ import { captureException } from '@sentry/core';
44 * Wraps an `app` directory server component with Sentry error instrumentation.
55 */
66export function wrapAppDirComponentWithSentry ( wrappingTarget : any ) : any {
7- // Super interesting: even though users may define server components as async functions, Next.js will turn them into
8- // synchronous functions and it will transform any`await`s into instances of the`use` hook. 🤯
7+ // Even though users may define server components as async functions, for the client bundles
8+ // Next.js will turn them into synchronous functionsf and it will transform any`await`s into instances of the`use`
9+ // hook. 🤯
910 return function sentryWrappedServerComponent ( this : unknown , ...args : any [ ] ) {
11+ let maybePromiseResult ;
12+
1013 try {
1114 // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
12- return wrappingTarget . apply ( this , args ) ;
15+ maybePromiseResult = wrappingTarget . apply ( this , args ) ;
1316 } catch ( e ) {
1417 captureException ( e ) ;
1518 throw e ;
1619 }
20+
21+ if ( typeof maybePromiseResult === 'object' && maybePromiseResult !== null && 'then' in maybePromiseResult ) {
22+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
23+ return maybePromiseResult . then ( null , ( e : Error ) => {
24+ captureException ( e ) ;
25+ throw e ;
26+ } ) ;
27+ } else {
28+ return maybePromiseResult ;
29+ }
1730 } ;
1831}
Original file line number Diff line number Diff line change @@ -4,15 +4,28 @@ import { captureException } from '@sentry/core';
44 * Wraps an `app` directory server component with Sentry error instrumentation.
55 */
66export function wrapAppDirComponentWithSentry ( wrappingTarget : any ) : any {
7- // Super interesting: even though users may define server components as async functions, Next.js will turn them into
8- // synchronous functions and it will transform any`await`s into instances of the`use` hook. 🤯
7+ // Even though users may define server components as async functions, for the client bundles
8+ // Next.js will turn them into synchronous functionsf and it will transform any`await`s into instances of the`use`
9+ // hook. 🤯
910 return function sentryWrappedServerComponent ( this : unknown , ...args : any [ ] ) {
11+ let maybePromiseResult ;
12+
1013 try {
1114 // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
12- return wrappingTarget . apply ( this , args ) ;
15+ maybePromiseResult = wrappingTarget . apply ( this , args ) ;
1316 } catch ( e ) {
1417 captureException ( e ) ;
1518 throw e ;
1619 }
20+
21+ if ( typeof maybePromiseResult === 'object' && maybePromiseResult !== null && 'then' in maybePromiseResult ) {
22+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
23+ return maybePromiseResult . then ( null , ( e : Error ) => {
24+ captureException ( e ) ;
25+ throw e ;
26+ } ) ;
27+ } else {
28+ return maybePromiseResult ;
29+ }
1730 } ;
1831}
You can’t perform that action at this time.
0 commit comments