-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathevent.ts
More file actions
46 lines (41 loc) · 1.19 KB
/
event.ts
File metadata and controls
46 lines (41 loc) · 1.19 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
import { log } from '../logger/logger';
/**
* Symbol to mark error as processed by Hawk
*/
const errorSentShadowProperty = Symbol('__hawk_processed__');
/**
* Check if the error has already been sent to Hawk.
*
* Motivation:
* Some integrations may catch errors on their own side and then normally re-throw them down.
* In this case, Hawk will catch the error again.
* We need to prevent this from happening.
*
* @param error - error object
*/
export function isErrorProcessed(error: unknown): boolean {
if (typeof error !== 'object' || error === null) {
return false;
}
return (error as Record<symbol, unknown>)[errorSentShadowProperty] === true;
}
/**
* Add non-enumerable property to the error object to mark it as processed.
*
* @param error - error object
*/
export function markErrorAsProcessed(error: unknown): void {
try {
if (typeof error !== 'object' || error === null) {
return;
}
Object.defineProperty(error, errorSentShadowProperty, {
enumerable: false, // Prevent from being collected by Hawk
value: true,
writable: true,
configurable: true,
});
} catch (e) {
log('Failed to mark error as processed', 'error', e);
}
}