forked from exceptionless/Exceptionless.JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimpleErrorPlugin.ts
More file actions
56 lines (48 loc) · 1.54 KB
/
SimpleErrorPlugin.ts
File metadata and controls
56 lines (48 loc) · 1.54 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 { EventPluginContext } from "../EventPluginContext.js";
import { IEventPlugin } from "../IEventPlugin.js";
import { isEmpty, stringify } from "../../Utils.js";
import { SimpleError } from "../../models/data/ErrorInfo.js";
import { KnownEventDataKeys } from "../../models/Event.js";
export const IgnoredErrorProperties: string[] = [
"arguments",
"column",
"columnNumber",
"description",
"fileName",
"message",
"name",
"number",
"line",
"lineNumber",
"opera#sourceloc",
"sourceId",
"sourceURL",
"stack",
"stackArray",
"stacktrace"
];
export class SimpleErrorPlugin implements IEventPlugin {
public priority = 30;
public name = "SimpleErrorPlugin";
public async run(context: EventPluginContext): Promise<void> {
const exception = context.eventContext.getException();
if (exception) {
context.event.type = "error";
if (context.event.data && !context.event.data[KnownEventDataKeys.SimpleError]) {
const error = <SimpleError>{
type: exception.name || "Error",
message: exception.message,
stack_trace: exception.stack,
data: {}
}
const exclusions = context.client.config.dataExclusions.concat(IgnoredErrorProperties);
const additionalData = JSON.parse(stringify(exception, exclusions)) as unknown;
if (!isEmpty(additionalData)) {
(error.data as Record<string, unknown>)["@ext"] = additionalData;
}
context.event.data[KnownEventDataKeys.SimpleError] = error;
}
}
return Promise.resolve();
}
}