-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathbugsnag-native.js
75 lines (72 loc) · 1.87 KB
/
bugsnag-native.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
export default class Bugsnag {
static notify(error) {
fetch('https://notify.bugsnag.com/', {
method: 'post',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify(this._build(error))
}).then(console.log).catch(console.log);
}
static _build(error) {
return {
apiKey: process.env.BUGSNAG_KEY,
notifier: {
name: 'React Native',
version: '1.0.11',
url: 'https://github.com/bugsnag/bugsnag-ruby'
},
events: [{
payloadVersion: '2',
exceptions: [{
errorClass: error.constructor.name || error.name || 'Error',
message: error.message,
stacktrace: this._processStackTrace(error)
}],
context: 'auth/session#create',
severity: 'error',
user: {
id: '19',
name: 'Simon Maynard',
email: '[email protected]'
},
app: {
version: '1.1.3',
releaseStage: 'production',
},
device: {
osVersion: '2.1.1',
hostname: 'web1.internal'
},
metaData: {
someData: {
key: 'value',
setOfKeys: {
key: 'value',
key2: 'value'
}
},
}
}]
};
}
static _processStackTrace(error) {
return [{
file: 'controllers/auth/session_controller.rb',
lineNumber: 1234,
columnNumber: 123,
method: 'create',
inProject: true,
}];
let blah = stacktrace.parse(error);
return callSites.map(function(callSite) {
return {
file: callSite.getFileName(),
method: callSite.getMethodName() || callSite.getFunctionName() || 'none',
lineNumber: callSite.getLineNumber(),
columnNumber: callSite.getColumnNumber()
};
});
}
}