forked from bugsnag/bugsnag-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
50 lines (43 loc) · 1.14 KB
/
index.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
import { ErrorHandler, Injectable } from '@angular/core'
import Bugsnag, { Client, Plugin } from '@bugsnag/js'
@Injectable()
export class BugsnagErrorHandler extends ErrorHandler {
public bugsnagClient: Client;
constructor (client?: Client) {
super()
if (client) {
this.bugsnagClient = client
} else {
this.bugsnagClient = ((Bugsnag as any)._client as Client)
}
}
public handleError (error: any): void {
const handledState = {
severity: 'error',
severityReason: { type: 'unhandledException' },
unhandled: true
}
const event = this.bugsnagClient.Event.create(
error,
true,
handledState,
'angular error handler',
1
)
if (error.ngDebugContext) {
event.addMetadata('angular', {
component: error.ngDebugContext.component,
context: error.ngDebugContext.context
})
}
this.bugsnagClient._notify(event)
ErrorHandler.prototype.handleError.call(this, error)
}
}
const plugin: Plugin = {
load: (client: Client): ErrorHandler => {
return new BugsnagErrorHandler(client)
},
name: 'Angular'
}
export default plugin