@@ -11,78 +11,82 @@ import { Utils } from '../Utils';
11
11
12
12
export class NodeBootstrapper implements IBootstrapper {
13
13
public register ( ) : void {
14
+ const beforeExit :string = 'beforeExit' ;
15
+ const uncaughtException :string = 'uncaughtException' ;
16
+
14
17
if ( ! ( typeof window === 'undefined' && typeof global !== 'undefined' && { } . toString . call ( global ) === '[object global]' ) ) {
15
18
return ;
16
19
}
17
20
18
- var configDefaults = Configuration . defaults ;
19
- configDefaults . environmentInfoCollector = new NodeEnvironmentInfoCollector ( ) ;
20
- configDefaults . errorParser = new NodeErrorParser ( ) ;
21
- configDefaults . requestInfoCollector = new NodeRequestInfoCollector ( ) ;
22
- configDefaults . submissionClient = new NodeSubmissionClient ( ) ;
21
+ var defaults = Configuration . defaults ;
22
+ defaults . environmentInfoCollector = new NodeEnvironmentInfoCollector ( ) ;
23
+ defaults . errorParser = new NodeErrorParser ( ) ;
24
+ defaults . requestInfoCollector = new NodeRequestInfoCollector ( ) ;
25
+ defaults . submissionClient = new NodeSubmissionClient ( ) ;
23
26
24
- process . on ( ' uncaughtException' , function ( error :Error ) {
25
- ExceptionlessClient . default . submitUnhandledException ( error , ' uncaughtException' ) ;
27
+ process . on ( uncaughtException , function ( error :Error ) {
28
+ ExceptionlessClient . default . submitUnhandledException ( error , uncaughtException ) ;
26
29
} ) ;
27
30
28
- process . on ( 'beforeExit' , ( code :number ) => {
29
- var client = ExceptionlessClient . default ;
31
+ process . on ( beforeExit , function ( code :number ) {
32
+ /**
33
+ * exit codes: https://nodejs.org/api/process.html#process_event_exit
34
+ */
35
+ function getExitCodeReason ( code :number ) : string {
36
+ if ( code === 1 ) {
37
+ return 'Uncaught Fatal Exception' ;
38
+ }
30
39
31
- var message = this . getExitCodeReason ( code ) ;
32
- if ( message !== null ) {
33
- client . submitLog ( 'beforeExit' , message , 'Error' )
34
- }
40
+ if ( code === 3 ) {
41
+ return 'Internal JavaScript Parse Error' ;
42
+ }
35
43
36
- client . config . queue . process ( )
37
- } ) ;
38
- }
44
+ if ( code === 4 ) {
45
+ return 'Internal JavaScript Evaluation Failure' ;
46
+ }
39
47
40
- // exit codes: https://nodejs.org/api/process.html#process_event_exit
41
- private getExitCodeReason ( code :number ) : string {
42
- if ( code === 1 ) {
43
- return 'Uncaught Fatal Exception' ;
44
- }
48
+ if ( code === 5 ) {
49
+ return 'Fatal Exception' ;
50
+ }
45
51
46
- if ( code === 3 ) {
47
- return 'Internal JavaScript Parse Error ' ;
48
- }
52
+ if ( code === 6 ) {
53
+ return 'Non-function Internal Exception Handler ' ;
54
+ }
49
55
50
- if ( code === 4 ) {
51
- return 'Internal JavaScript Evaluation Failure' ;
52
- }
56
+ if ( code === 7 ) {
57
+ return 'Internal Exception Handler Run-Time Failure' ;
58
+ }
53
59
54
- if ( code === 5 ) {
55
- return 'Fatal Exception' ;
56
- }
60
+ if ( code === 8 ) {
61
+ return 'Uncaught Exception' ;
62
+ }
57
63
58
- if ( code === 6 ) {
59
- return 'Non-function Internal Exception Handler ';
60
- }
64
+ if ( code === 9 ) {
65
+ return 'Invalid Argument ';
66
+ }
61
67
62
- if ( code === 7 ) {
63
- return 'Internal Exception Handler Run-Time Failure' ;
64
- }
68
+ if ( code === 10 ) {
69
+ return 'Internal JavaScript Run-Time Failure' ;
70
+ }
65
71
66
- if ( code === 8 ) {
67
- return 'Uncaught Exception' ;
68
- }
69
-
70
- if ( code === 9 ) {
71
- return 'Invalid Argument' ;
72
- }
72
+ if ( code === 12 ) {
73
+ return 'Invalid Debug Argument' ;
74
+ }
73
75
74
- if ( code === 10 ) {
75
- return 'Internal JavaScript Run-Time Failure ';
76
- }
76
+ if ( code > 128 ) {
77
+ return 'Signal Exits ';
78
+ }
77
79
78
- if ( code === 12 ) {
79
- return 'Invalid Debug Argument' ;
80
- }
80
+ return null ;
81
+ }
81
82
82
- if ( code > 128 ) {
83
- return 'Signal Exits' ;
84
- }
83
+ var client = ExceptionlessClient . default ;
84
+ var message = getExitCodeReason ( code ) ;
85
+ if ( message !== null ) {
86
+ client . submitLog ( beforeExit , message , 'Error' )
87
+ }
85
88
86
- return null ;
89
+ client . config . queue . process ( )
90
+ } ) ;
87
91
}
88
92
}
0 commit comments