/
ember.ts
93 lines (84 loc) · 2.3 KB
/
ember.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
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
import { captureMessage, getCurrentHub, Scope, withScope } from '@sentry/core';
import { Integration, SentryEvent } from '@sentry/types';
import { getGlobalObject } from '@sentry/utils/misc';
/** JSDoc */
export class Ember implements Integration {
/**
* @inheritDoc
*/
public name: string = Ember.id;
/**
* @inheritDoc
*/
public static id: string = 'Ember';
/**
* @inheritDoc
*/
private readonly Ember: any; // tslint:disable-line:variable-name
/**
* @inheritDoc
*/
public constructor(options: { Ember?: any } = {}) {
this.Ember =
options.Ember ||
(getGlobalObject() as {
Ember: any;
}).Ember;
}
/**
* @inheritDoc
*/
public setupOnce(): void {
if (!this.Ember) {
return;
}
const oldOnError = this.Ember.onerror;
this.Ember.onerror = (error: Error): void => {
if (getCurrentHub().getIntegration(Ember)) {
withScope(scope => {
this.addIntegrationToSdkInfo(scope);
getCurrentHub().captureException(error, { originalException: error });
});
}
if (typeof oldOnError === 'function') {
oldOnError.call(this.Ember, error);
} else if (this.Ember.testing) {
throw error;
}
};
this.Ember.RSVP.on(
'error',
(reason: any): void => {
if (getCurrentHub().getIntegration(Ember)) {
withScope(scope => {
if (reason instanceof Error) {
scope.setExtra('context', 'Unhandled Promise error detected');
this.addIntegrationToSdkInfo(scope);
getCurrentHub().captureException(reason, { originalException: reason });
} else {
scope.setExtra('reason', reason);
this.addIntegrationToSdkInfo(scope);
captureMessage('Unhandled Promise error detected');
}
});
}
},
);
}
/**
* Appends SDK integrations
* @param scope The scope currently used.
*/
private addIntegrationToSdkInfo(scope: Scope): void {
scope.addEventProcessor(async (event: SentryEvent) => {
if (event.sdk) {
const integrations = event.sdk.integrations || [];
event.sdk = {
...event.sdk,
integrations: [...integrations, 'ember'],
};
}
return event;
});
}
}