/
crashReporting.ts
62 lines (57 loc) · 1.77 KB
/
crashReporting.ts
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
/**
* If you're using Sentry
* Expo https://docs.expo.dev/guides/using-sentry/
*/
// import * as Sentry from "@sentry/react-native"
/**
* If you're using Crashlytics: https://rnfirebase.io/crashlytics/usage
*/
// import crashlytics from "@react-native-firebase/crashlytics"
/**
* If you're using Bugsnag:
* RN https://docs.bugsnag.com/platforms/react-native/)
* Expo https://docs.bugsnag.com/platforms/react-native/expo/
*/
// import Bugsnag from "@bugsnag/react-native"
// import Bugsnag from "@bugsnag/expo"
/**
* This is where you put your crash reporting service initialization code to call in `./app/app.tsx`
*/
export const initCrashReporting = () => {
// Sentry.init({
// dsn: "YOUR DSN HERE",
// debug: true, // If `true`, Sentry will try to print out useful debugging information if something goes wrong with sending the event. Set it to `false` in production
// })
// Bugsnag.start("YOUR API KEY")
}
/**
* Error classifications used to sort errors on error reporting services.
*/
export enum ErrorType {
/**
* An error that would normally cause a red screen in dev
* and force the user to sign out and restart.
*/
FATAL = "Fatal",
/**
* An error caught by try/catch where defined using Reactotron.tron.error.
*/
HANDLED = "Handled",
}
/**
* Manually report a handled error.
*/
export const reportCrash = (error: Error, type: ErrorType = ErrorType.FATAL) => {
if (__DEV__) {
// Log to console and Reactotron in development
const message = error.message || "Unknown"
console.error(error)
console.log(message, type)
} else {
// In production, utilize crash reporting service of choice below:
// RN
// Sentry.captureException(error)
// crashlytics().recordError(error)
// Bugsnag.notify(error)
}
}