Skip to content

Commit fee1d18

Browse files
committed
add mechanism
1 parent b563a26 commit fee1d18

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

packages/react-router/src/server/createSentryHandleError.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@ export function createSentryHandleError({ logErrors = false }: SentryHandleError
1717
): Promise<void> {
1818
// React Router may abort some interrupted requests, don't report those
1919
if (!args.request.signal.aborted) {
20-
captureException(error);
20+
captureException(error, {
21+
mechanism: {
22+
type: 'react-router',
23+
handled: false,
24+
},
25+
});
2126
if (logErrors) {
2227
// eslint-disable-next-line no-console
2328
console.error(error);

packages/react-router/test/server/createSentryHandleError.test.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ vi.mock('@sentry/core', () => ({
88
flushIfServerless: vi.fn().mockResolvedValue(undefined),
99
}));
1010

11+
const mechanism = {
12+
handled: false,
13+
type: 'react-router',
14+
};
15+
1116
describe('createSentryHandleError', () => {
1217
const mockCaptureException = vi.mocked(core.captureException);
1318
const mockFlushIfServerless = vi.mocked(core.flushIfServerless);
@@ -50,7 +55,7 @@ describe('createSentryHandleError', () => {
5055

5156
await handleError(mockError, mockArgs);
5257

53-
expect(mockCaptureException).toHaveBeenCalledWith(mockError);
58+
expect(mockCaptureException).toHaveBeenCalledWith(mockError, { mechanism });
5459
expect(mockFlushIfServerless).toHaveBeenCalled();
5560
expect(mockConsoleError).not.toHaveBeenCalled();
5661
});
@@ -74,7 +79,7 @@ describe('createSentryHandleError', () => {
7479

7580
await handleError(mockError, mockArgs);
7681

77-
expect(mockCaptureException).toHaveBeenCalledWith(mockError);
82+
expect(mockCaptureException).toHaveBeenCalledWith(mockError, { mechanism });
7883
expect(mockFlushIfServerless).toHaveBeenCalled();
7984
expect(mockConsoleError).toHaveBeenCalledWith(mockError);
8085
});
@@ -98,7 +103,7 @@ describe('createSentryHandleError', () => {
98103

99104
await handleError(mockError, mockArgs);
100105

101-
expect(mockCaptureException).toHaveBeenCalledWith(mockError);
106+
expect(mockCaptureException).toHaveBeenCalledWith(mockError, { mechanism });
102107
expect(mockFlushIfServerless).toHaveBeenCalled();
103108
expect(mockConsoleError).not.toHaveBeenCalled();
104109
});
@@ -112,7 +117,7 @@ describe('createSentryHandleError', () => {
112117

113118
await handleError(stringError, mockArgs);
114119

115-
expect(mockCaptureException).toHaveBeenCalledWith(stringError);
120+
expect(mockCaptureException).toHaveBeenCalledWith(stringError, { mechanism });
116121
expect(mockFlushIfServerless).toHaveBeenCalled();
117122
});
118123

@@ -122,7 +127,7 @@ describe('createSentryHandleError', () => {
122127

123128
await handleError(null, mockArgs);
124129

125-
expect(mockCaptureException).toHaveBeenCalledWith(null);
130+
expect(mockCaptureException).toHaveBeenCalledWith(null, { mechanism });
126131
expect(mockFlushIfServerless).toHaveBeenCalled();
127132
});
128133

@@ -133,7 +138,7 @@ describe('createSentryHandleError', () => {
133138

134139
await handleError(customError, mockArgs);
135140

136-
expect(mockCaptureException).toHaveBeenCalledWith(customError);
141+
expect(mockCaptureException).toHaveBeenCalledWith(customError, { mechanism });
137142
expect(mockFlushIfServerless).toHaveBeenCalled();
138143
});
139144
});
@@ -145,7 +150,7 @@ describe('createSentryHandleError', () => {
145150

146151
await handleError(mockError, mockArgs);
147152

148-
expect(mockCaptureException).toHaveBeenCalledWith(mockError);
153+
expect(mockCaptureException).toHaveBeenCalledWith(mockError, { mechanism });
149154
expect(mockFlushIfServerless).toHaveBeenCalled();
150155
expect(mockConsoleError).toHaveBeenCalledWith(mockError);
151156
});
@@ -177,7 +182,7 @@ describe('createSentryHandleError', () => {
177182
await handleErrorPromise;
178183
const endTime = Date.now();
179184

180-
expect(mockCaptureException).toHaveBeenCalledWith(mockError);
185+
expect(mockCaptureException).toHaveBeenCalledWith(mockError, { mechanism });
181186
expect(mockFlushIfServerless).toHaveBeenCalled();
182187
expect(endTime - startTime).toBeGreaterThanOrEqual(10);
183188
});
@@ -193,7 +198,7 @@ describe('createSentryHandleError', () => {
193198
// This should not throw
194199
await expect(handleError(mockError, mockArgs)).resolves.toBeUndefined();
195200

196-
expect(mockCaptureException).toHaveBeenCalledWith(mockError);
201+
expect(mockCaptureException).toHaveBeenCalledWith(mockError, { mechanism });
197202
expect(mockFlushIfServerless).toHaveBeenCalled();
198203
});
199204
});

0 commit comments

Comments
 (0)