forked from exceptionless/Exceptionless.JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNodeLifeCyclePlugin.ts
More file actions
81 lines (63 loc) · 1.79 KB
/
NodeLifeCyclePlugin.ts
File metadata and controls
81 lines (63 loc) · 1.79 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import {
ExceptionlessClient,
IEventPlugin,
PluginContext
} from "@exceptionless/core";
export class NodeLifeCyclePlugin implements IEventPlugin {
public priority: number = 105;
public name: string = "NodeLifeCyclePlugin";
private _client: ExceptionlessClient | null = null;
public startup(context: PluginContext): Promise<void> {
if (this._client) {
return Promise.resolve();
}
this._client = context.client;
process.on("beforeExit", (code: number) => {
const message = this.getExitCodeReason(code);
if (message) {
void this._client?.submitLog("beforeExit", message, "Error");
}
void this._client?.suspend();
// Application will now exit.
});
return Promise.resolve();
}
/**
* exit codes: https://nodejs.org/api/process.html#process_event_exit
* From now on, only synchronous code may run. As soon as this method
* ends, the application inevitably will exit.
*/
private getExitCodeReason(exitCode: number): string | null {
if (exitCode === 1) {
return "Uncaught Fatal Exception";
}
if (exitCode === 3) {
return "Internal JavaScript Parse Error";
}
if (exitCode === 4) {
return "Internal JavaScript Evaluation Failure";
}
if (exitCode === 5) {
return "Fatal Exception";
}
if (exitCode === 6) {
return "Non-function Internal Exception Handler ";
}
if (exitCode === 7) {
return "Internal Exception Handler Run-Time Failure";
}
if (exitCode === 8) {
return "Uncaught Exception";
}
if (exitCode === 9) {
return "Invalid Argument";
}
if (exitCode === 10) {
return "Internal JavaScript Run-Time Failure";
}
if (exitCode === 12) {
return "Invalid Debug Argument";
}
return null;
}
}