-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy patherrors.tsx
More file actions
65 lines (60 loc) · 2.02 KB
/
Copy patherrors.tsx
File metadata and controls
65 lines (60 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import { captureException, withScope } from '@sentry/core';
import { addExceptionMechanism, isNodeEnv, isString } from '@sentry/utils';
import type { ErrorResponse } from '../utils/vendor/types';
/**
* Checks whether the given error is an ErrorResponse.
* ErrorResponse is when users throw a response from their loader or action functions.
* This is in fact a server-side error that we capture on the client.
*
* @param error The error to check.
* @returns boolean
*/
function isErrorResponse(error: unknown): error is ErrorResponse {
return typeof error === 'object' && error !== null && 'status' in error && 'statusText' in error;
}
/**
* Captures an error that is thrown inside a Remix ErrorBoundary.
*
* @param error The error to capture.
* @returns void
*/
export function captureRemixErrorBoundaryError(error: unknown): void {
const isClientSideRuntimeError = !isNodeEnv() && error instanceof Error;
const isRemixErrorResponse = isErrorResponse(error);
// Server-side errors apart from `ErrorResponse`s also appear here without their stacktraces.
// So, we only capture:
// 1. `ErrorResponse`s
// 2. Client-side runtime errors here,
// And other server - side errors in `handleError` function where stacktraces are available.
if (isRemixErrorResponse || isClientSideRuntimeError) {
const eventData = isRemixErrorResponse
? {
function: 'ErrorResponse',
...error.data,
}
: {
function: 'ReactError',
};
withScope(scope => {
scope.addEventProcessor(event => {
addExceptionMechanism(event, {
type: 'instrument',
handled: false,
data: eventData,
});
return event;
});
if (isRemixErrorResponse) {
if (isString(error.data)) {
captureException(error.data);
} else if (error.statusText) {
captureException(error.statusText);
} else {
captureException(error);
}
} else {
captureException(error);
}
});
}
}