forked from corymsmith/react-native-fabric
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCrashlytics.js
96 lines (82 loc) · 2.59 KB
/
Crashlytics.js
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/**
* @providesModule Crashlytics
*/
// @flow
import { NativeModules, Platform } from 'react-native'
const SMXCrashlytics = NativeModules.SMXCrashlytics
export const Crashlytics = {
crash: SMXCrashlytics.crash,
throwException: SMXCrashlytics.throwException,
/**
* Convert error into something the native code knows what to do with.
* Attempts to be flexible and accept error objects in different formats.
* We need to be careful which data types we send to the native layer.
* Could do something much fancier here, e.g., deep, recursive serialization
* (or "flattening") but keep it simple for now.
* @param error
*/
recordError: function(error: mixed) {
var newError
if (typeof error === 'string' || error instanceof String) {
newError = { domain: error }
} else if (typeof error === 'number') {
newError = { code: error }
} else if (typeof error === 'object') {
newError = {}
// Pass everything in as a string or number to be safe
for (var k in error) {
if (error.hasOwnProperty(k)) {
if (
typeof error[k] !== 'number' &&
typeof error[k] !== 'string' &&
!(error[k] instanceof String)
) {
newError[k] = JSON.stringify(error[k])
} else {
newError[k] = error[k]
}
}
}
} else {
// Array?
// Fall back on JSON
newError = {
json: JSON.stringify(error),
}
}
SMXCrashlytics.recordError(newError)
},
logException: function(value: string) {
SMXCrashlytics.logException(value)
},
log: function(message: string) {
SMXCrashlytics.log(message)
},
setUserEmail: function(email: string | null) {
SMXCrashlytics.setUserEmail(email)
},
setUserIdentifier: function(userIdentifier: string | null) {
SMXCrashlytics.setUserIdentifier(userIdentifier)
},
setUserName: function(userName: string | null) {
SMXCrashlytics.setUserName(userName)
},
setBool: function(key: string, value: boolean) {
SMXCrashlytics.setBool(key, value)
},
setNumber: function(key: string, value: number) {
// This is a hack but allows us to have a standard API for both platforms
if (Platform.OS === 'android') SMXCrashlytics.setNumber(key, value + '')
else SMXCrashlytics.setNumber(key, value)
},
setString: function(key: string, value: string) {
SMXCrashlytics.setString(key, value)
},
recordCustomExceptionName: function(
name: string,
reason: string,
stack?: Object[]
) {
SMXCrashlytics.recordCustomExceptionName(name, reason, stack || [])
},
}