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
56 lines (50 loc) · 1.57 KB
/
ErrorPlugin.ts
File metadata and controls
56 lines (50 loc) · 1.57 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
import { KnownEventDataKeys } from "../../models/Event.js";
import { stringify, isEmpty } from "../../Utils.js";
import { EventPluginContext } from "../EventPluginContext.js";
import { IEventPlugin } from "../IEventPlugin.js";
export class ErrorPlugin implements IEventPlugin {
public priority: number = 30;
public name: string = "ErrorPlugin";
public async run(context: EventPluginContext): Promise<void> {
const IGNORED_ERROR_PROPERTIES: string[] = [
"arguments",
"column",
"columnNumber",
"description",
"fileName",
"message",
"name",
"number",
"line",
"lineNumber",
"opera#sourceloc",
"sourceId",
"sourceURL",
"stack",
"stackArray",
"stacktrace"
];
const exception = context.contextData.getException();
if (exception) {
context.event.type = "error";
if (!context.event.data[KnownEventDataKeys.Error]) {
const config = context.client.config;
const parser = config.errorParser;
if (!parser) {
throw new Error("No error parser was defined.");
}
const result = await parser.parse(context, exception);
if (result) {
const additionalData = JSON.parse(stringify(exception, config.dataExclusions.concat(IGNORED_ERROR_PROPERTIES)));
if (!isEmpty(additionalData)) {
if (!result.data) {
result.data = {};
}
result.data["@ext"] = additionalData;
}
context.event.data[KnownEventDataKeys.Error] = result;
}
}
}
}
}