forked from exceptionless/Exceptionless.JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathErrorPlugin.ts
More file actions
31 lines (25 loc) · 870 Bytes
/
ErrorPlugin.ts
File metadata and controls
31 lines (25 loc) · 870 Bytes
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
import { IEventPlugin } from '../IEventPlugin';
import { EventPluginContext } from '../EventPluginContext';
export class ErrorPlugin implements IEventPlugin {
public priority:number = 30;
public name:string = 'ErrorPlugin';
run(context:EventPluginContext): Promise<any> {
var exception = context.contextData.getException();
if (exception == null) {
return Promise.resolve();
}
if (!context.event.data) {
context.event.data = {};
}
context.event.type = 'error';
if (!!context.event.data['@error']) {
return Promise.resolve();
}
var parser = context.client.config.errorParser;
if (!parser) {
context.cancel = true;
return Promise.reject(new Error('No error parser was defined. This exception will be discarded.'))
}
return parser.parse(context, context.event.data['@error']);
}
}