-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30337 from pasyukevich/feature/migrate-ErrorBoundary
[No QA] [TS Migration] Migrate 'ErrorBoundary' component to TypeScript
- Loading branch information
Showing
6 changed files
with
73 additions
and
45 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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,30 @@ | ||
import crashlytics from '@react-native-firebase/crashlytics'; | ||
import React from 'react'; | ||
import Log from '@libs/Log'; | ||
import BaseErrorBoundary from './BaseErrorBoundary'; | ||
import {BaseErrorBoundaryProps, LogError} from './types'; | ||
|
||
const logError: LogError = (errorMessage, error, errorInfo) => { | ||
// Log the error to the server | ||
Log.alert(`${errorMessage} - ${error.message}`, {errorInfo}, false); | ||
|
||
/* On native we also log the error to crashlytics | ||
* Since the error was handled we need to manually tell crashlytics about it */ | ||
crashlytics().log(`errorInfo: ${errorInfo}`); | ||
crashlytics().recordError(error); | ||
}; | ||
|
||
function ErrorBoundary({errorMessage, children}: Omit<BaseErrorBoundaryProps, 'logError'>) { | ||
return ( | ||
<BaseErrorBoundary | ||
errorMessage={errorMessage} | ||
logError={logError} | ||
> | ||
{children} | ||
</BaseErrorBoundary> | ||
); | ||
} | ||
|
||
ErrorBoundary.displayName = 'ErrorBoundary'; | ||
|
||
export default ErrorBoundary; |
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,24 @@ | ||
import React from 'react'; | ||
import Log from '@libs//Log'; | ||
import BaseErrorBoundary from './BaseErrorBoundary'; | ||
import {BaseErrorBoundaryProps, LogError} from './types'; | ||
|
||
const logError: LogError = (errorMessage, error, errorInfo) => { | ||
// Log the error to the server | ||
Log.alert(`${errorMessage} - ${error.message}`, {errorInfo}, false); | ||
}; | ||
|
||
function ErrorBoundary({errorMessage, children}: Omit<BaseErrorBoundaryProps, 'logError'>) { | ||
return ( | ||
<BaseErrorBoundary | ||
errorMessage={errorMessage} | ||
logError={logError} | ||
> | ||
{children} | ||
</BaseErrorBoundary> | ||
); | ||
} | ||
|
||
ErrorBoundary.displayName = 'ErrorBoundary'; | ||
|
||
export default ErrorBoundary; |
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,14 @@ | ||
type LogError = (message: string, error: Error, errorInfo: string) => void; | ||
|
||
type BaseErrorBoundaryProps = { | ||
/* A message posted to `logError` (along with error data) when this component intercepts an error */ | ||
errorMessage: string; | ||
|
||
/* A function to perform the actual logging since different platforms support different tools */ | ||
logError?: LogError; | ||
|
||
/* Actual content wrapped by this error boundary */ | ||
children: React.ReactNode; | ||
}; | ||
|
||
export type {BaseErrorBoundaryProps, LogError}; |