forked from jasonmit/ember-new-relic
/
new-relic.js
59 lines (45 loc) · 1.3 KB
/
new-relic.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
import Ember from 'ember';
export function initialize() {
const { NREUM } = window;
if (!NREUM) {
return;
}
function mustIgnoreError(error) {
// Ember 2.X seems to not catch `TransitionAborted` errors caused by regular redirects. We don't want these errors to show up in NewRelic so we have to filter them ourselfs.
// Once the issue https://github.com/emberjs/ember.js/issues/12505 is resolved we can remove this ignored error.
if (Ember.isNone(error)) {
return false;
}
const errorName = Ember.get(error, 'name');
return errorName === 'TransitionAborted';
}
function handleError(error, shouldThrowError = true) {
if (mustIgnoreError(error)) {
return;
}
try {
NREUM.noticeError(error);
} catch(e) {
// Ignore
}
// Ensure we don't throw errors with `Logger.error`
if (Ember.testing && shouldThrowError) {
throw error;
}
console.error(error);
}
function generateError(cause, stack) {
const error = new Error(cause);
error.stack = stack;
return error;
}
Ember.onerror = handleError;
Ember.RSVP.on('error', handleError);
Ember.Logger.error = function(...messages) {
handleError(generateError(messages.join(' ')), false);
};
}
export default {
name: 'new-relic',
initialize
};