forked from exceptionless/Exceptionless.JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNodeGlobalHandlerPlugin.ts
More file actions
31 lines (24 loc) · 877 Bytes
/
NodeGlobalHandlerPlugin.ts
File metadata and controls
31 lines (24 loc) · 877 Bytes
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
import {
ExceptionlessClient,
IEventPlugin,
PluginContext
} from "@exceptionless/core";
export class NodeGlobalHandlerPlugin implements IEventPlugin {
public priority: number = 100;
public name: string = "NodeGlobalHandlerPlugin";
private _client: ExceptionlessClient = null;
public startup(context: PluginContext): Promise<void> {
if (this._client) {
return Promise.resolve();
}
this._client = context.client;
Error.stackTraceLimit = 50;
process.addListener("uncaughtException", (error: Error) => {
void this._client?.submitUnhandledException(error, "uncaughtException");
});
process.addListener("unhandledRejection", (reason: unknown | null | undefined, promise: Promise<any>) => {
void this._client?.submitUnhandledException(<Error>reason, "unhandledRejection");
});
return Promise.resolve();
}
}