|
3 | 3 | captureException,
|
4 | 4 | continueTrace,
|
5 | 5 | getCurrentScope,
|
| 6 | + handleCallbackErrors, |
6 | 7 | runWithAsyncContext,
|
7 | 8 | startSpanManual,
|
8 | 9 | } from '@sentry/core';
|
@@ -69,50 +70,35 @@ export function wrapServerComponentWithSentry<F extends (...args: any[]) => any>
|
69 | 70 | },
|
70 | 71 | },
|
71 | 72 | span => {
|
72 |
| - try { |
73 |
| - const res = originalFunction.apply(thisArg, args); |
74 |
| - span?.end(); |
75 |
| - return res; |
76 |
| - } catch (error) { |
77 |
| - if (isNotFoundNavigationError(error)) { |
78 |
| - // We don't want to report "not-found"s |
79 |
| - span?.setStatus('not_found'); |
80 |
| - } else if (isRedirectNavigationError(error)) { |
81 |
| - // We don't want to report redirects |
82 |
| - // Since `startSpan` will automatically set the span status to "internal_error" when an error is thrown, |
83 |
| - // We cannot set it to `ok` as that will lead to `startSpanManual` overwriting it when the error bubbles up, |
84 |
| - // so instead we temp. set this to `cancelled` and handle this later before we end the span. |
85 |
| - span?.setStatus('ok'); |
86 |
| - } else { |
87 |
| - span?.setStatus('internal_error'); |
| 73 | + return handleCallbackErrors( |
| 74 | + () => originalFunction.apply(thisArg, args), |
| 75 | + error => { |
| 76 | + if (isNotFoundNavigationError(error)) { |
| 77 | + // We don't want to report "not-found"s |
| 78 | + span?.setStatus('not_found'); |
| 79 | + } else if (isRedirectNavigationError(error)) { |
| 80 | + // We don't want to report redirects |
| 81 | + span?.setStatus('ok'); |
| 82 | + } else { |
| 83 | + span?.setStatus('internal_error'); |
88 | 84 |
|
89 |
| - captureException(error, { |
90 |
| - mechanism: { |
91 |
| - handled: false, |
92 |
| - }, |
93 |
| - }); |
94 |
| - } |
95 |
| - |
96 |
| - span?.end(); |
97 |
| - |
98 |
| - // flushQueue should not throw |
99 |
| - // eslint-disable-next-line @typescript-eslint/no-floating-promises |
100 |
| - flushQueue(); |
101 |
| - |
102 |
| - // flushQueue should not throw |
103 |
| - // eslint-disable-next-line @typescript-eslint/no-floating-promises |
104 |
| - flushQueue(); |
| 85 | + captureException(error, { |
| 86 | + mechanism: { |
| 87 | + handled: false, |
| 88 | + }, |
| 89 | + }); |
| 90 | + } |
| 91 | + }, |
| 92 | + () => { |
| 93 | + span?.end(); |
105 | 94 |
|
106 |
| - throw error; |
107 |
| - } |
| 95 | + // flushQueue should not throw |
| 96 | + // eslint-disable-next-line @typescript-eslint/no-floating-promises |
| 97 | + flushQueue(); |
| 98 | + }, |
| 99 | + ); |
108 | 100 | },
|
109 | 101 | );
|
110 |
| - |
111 |
| - // flushQueue should not throw |
112 |
| - // eslint-disable-next-line @typescript-eslint/no-floating-promises |
113 |
| - flushQueue(); |
114 |
| - |
115 |
| - return res; |
116 | 102 | });
|
117 | 103 | },
|
118 | 104 | });
|
|
0 commit comments