forked from exceptionless/Exceptionless.JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathContextData.ts
More file actions
43 lines (34 loc) · 1.05 KB
/
ContextData.ts
File metadata and controls
43 lines (34 loc) · 1.05 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
const enum KnownContextKeys {
Exception = "@@_Exception",
IsUnhandledError = "@@_IsUnhandledError",
SubmissionMethod = "@@_SubmissionMethod"
}
// TODO: Look into ways of improving this.
export class ContextData implements Record<string, unknown> {
[x: string]: unknown;
public getException(): Error | null {
return this[KnownContextKeys.Exception] as Error || null;
}
public setException(exception: Error): void {
if (exception) {
this[KnownContextKeys.Exception] = exception;
}
}
public get hasException(): boolean {
return !!this[KnownContextKeys.Exception];
}
public markAsUnhandledError(): void {
this[KnownContextKeys.IsUnhandledError] = true;
}
public get isUnhandledError(): boolean {
return !!this[KnownContextKeys.IsUnhandledError];
}
public getSubmissionMethod(): string | null {
return this[KnownContextKeys.SubmissionMethod] as string || null;
}
public setSubmissionMethod(method: string): void {
if (method) {
this[KnownContextKeys.SubmissionMethod] = method;
}
}
}