-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9c86bf4
commit decae61
Showing
14 changed files
with
220 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { captureException, withScope } from '@sentry/core'; | ||
import { addExceptionMechanism, isNodeEnv, isString } from '@sentry/utils'; | ||
|
||
import type { ErrorResponse } from '../utils/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: true, | ||
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); | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { GLOBAL_OBJ } from '@sentry/utils'; | ||
|
||
import type { FutureConfig, ServerBuild } from './types'; | ||
|
||
export type EnhancedGlobal = typeof GLOBAL_OBJ & { | ||
__remixContext?: { | ||
future?: FutureConfig; | ||
}; | ||
}; | ||
|
||
/** | ||
* Get the future flags from the Remix browser context | ||
* | ||
* @returns The future flags | ||
*/ | ||
export function getFutureFlagsBrowser(): FutureConfig | undefined { | ||
const window = GLOBAL_OBJ as EnhancedGlobal; | ||
|
||
if (!window.__remixContext) { | ||
return; | ||
} | ||
|
||
return window.__remixContext.future; | ||
} | ||
|
||
/** | ||
* Get the future flags from the Remix server build | ||
* | ||
* @param build The Remix server build | ||
* | ||
* @returns The future flags | ||
*/ | ||
export function getFutureFlagsServer(build: ServerBuild): FutureConfig | undefined { | ||
return build.future; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.