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
74 lines (65 loc) · 1.87 KB
/
ErrorPlugin.ts
File metadata and controls
74 lines (65 loc) · 1.87 KB
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
import { IEventPlugin } from '../IEventPlugin';
import { EventPluginContext } from '../EventPluginContext';
export class ErrorPlugin implements IEventPlugin {
public priority: number = 30;
public name: string = 'ErrorPlugin';
public ignoredProperties: string[] = [
'arguments',
'column',
'columnNumber',
'description',
'fileName',
'message',
'name',
'number',
'line',
'lineNumber',
'opera#sourceloc',
'sourceId',
'sourceURL',
'stack',
'stackArray',
'stacktrace'
];
public run(context: EventPluginContext, next?: () => void): void {
const ERROR_KEY: string = '@error'; // optimization for minifier.
const EXTRA_PROPERTIES_KEY: string = '@ext';
let exception = context.contextData.getException();
if (!!exception) {
context.event.type = 'error';
if (!context.event.data[ERROR_KEY]) {
let parser = context.client.config.errorParser;
if (!parser) {
throw new Error('No error parser was defined.');
}
let result = parser.parse(context, exception);
if (!!result) {
let additionalData = this.getAdditionalData(exception);
if (!!additionalData) {
if (!result.data) {
result.data = {};
}
result.data[EXTRA_PROPERTIES_KEY] = additionalData;
}
context.event.data[ERROR_KEY] = result;
}
}
}
next && next();
}
private getAdditionalData(exception: Error): { [key: string]: any } {
let additionalData = {};
for (var key in exception) {
if (this.ignoredProperties.indexOf(key) >= 0) {
continue;
}
let value = exception[key];
if (typeof value !== 'function') {
additionalData[key] = value;
}
}
return Object.getOwnPropertyNames(additionalData).length
? additionalData
: null;
}
}