forked from exceptionless/Exceptionless.JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNodeBootstrapper.ts
More file actions
88 lines (70 loc) · 2.53 KB
/
NodeBootstrapper.ts
File metadata and controls
88 lines (70 loc) · 2.53 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
82
83
84
85
86
87
88
import { IBootstrapper } from 'IBootstrapper';
import { Configuration } from '../configuration/Configuration';
import { IConfigurationSettings } from '../configuration/IConfigurationSettings';
import { IError } from '../models/IError';
import { NodeEnvironmentInfoCollector } from '../services/NodeEnvironmentInfoCollector';
import { NodeErrorParser } from '../services/NodeErrorParser';
import { NodeRequestInfoCollector } from '../services/NodeRequestInfoCollector';
import { NodeSubmissionClient } from '../submission/NodeSubmissionClient';
import { ExceptionlessClient } from '../ExceptionlessClient';
import { Utils } from '../Utils';
export class NodeBootstrapper implements IBootstrapper {
public register(): void {
if (!(typeof window === 'undefined' && typeof global !== 'undefined' && {}.toString.call(global) === '[object global]')) {
return;
}
var configDefaults = Configuration.defaults;
configDefaults.environmentInfoCollector = new NodeEnvironmentInfoCollector();
configDefaults.errorParser = new NodeErrorParser();
configDefaults.requestInfoCollector = new NodeRequestInfoCollector();
configDefaults.submissionClient = new NodeSubmissionClient();
process.on('uncaughtException', function(error) {
ExceptionlessClient.default.submitUnhandledException(error, 'uncaughtException');
});
process.on('beforeExit', (code:number) => {
var client = ExceptionlessClient.default;
var message = this.getExitCodeReason(code);
if (message !== null) {
client.submitLog('beforeExit', message, 'Error')
}
client.config.queue.process()
});
}
// exit codes: https://nodejs.org/api/process.html#process_event_exit
private getExitCodeReason(code:number): string {
if (code === 1) {
return 'Uncaught Fatal Exception';
}
if (code === 3) {
return 'Internal JavaScript Parse Error';
}
if (code === 4) {
return 'Internal JavaScript Evaluation Failure';
}
if (code === 5) {
return 'Fatal Exception';
}
if (code === 6) {
return 'Non-function Internal Exception Handler ';
}
if (code === 7) {
return 'Internal Exception Handler Run-Time Failure';
}
if (code === 8) {
return 'Uncaught Exception';
}
if (code === 9) {
return 'Invalid Argument';
}
if (code === 10) {
return 'Internal JavaScript Run-Time Failure';
}
if (code === 12) {
return 'Invalid Debug Argument';
}
if (code > 128) {
return 'Signal Exits';
}
return null;
}
}