@@ -11,78 +11,82 @@ import { Utils } from '../Utils';
1111
1212export class NodeBootstrapper implements IBootstrapper {
1313 public register ( ) : void {
14+ const beforeExit :string = 'beforeExit' ;
15+ const uncaughtException :string = 'uncaughtException' ;
16+
1417 if ( ! ( typeof window === 'undefined' && typeof global !== 'undefined' && { } . toString . call ( global ) === '[object global]' ) ) {
1518 return ;
1619 }
1720
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 ( ) ;
2326
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 ) ;
2629 } ) ;
2730
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+ }
3039
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+ }
3543
36- client . config . queue . process ( )
37- } ) ;
38- }
44+ if ( code === 4 ) {
45+ return 'Internal JavaScript Evaluation Failure' ;
46+ }
3947
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+ }
4551
46- if ( code === 3 ) {
47- return 'Internal JavaScript Parse Error ' ;
48- }
52+ if ( code === 6 ) {
53+ return 'Non-function Internal Exception Handler ' ;
54+ }
4955
50- if ( code === 4 ) {
51- return 'Internal JavaScript Evaluation Failure' ;
52- }
56+ if ( code === 7 ) {
57+ return 'Internal Exception Handler Run-Time Failure' ;
58+ }
5359
54- if ( code === 5 ) {
55- return 'Fatal Exception' ;
56- }
60+ if ( code === 8 ) {
61+ return 'Uncaught Exception' ;
62+ }
5763
58- if ( code === 6 ) {
59- return 'Non-function Internal Exception Handler ';
60- }
64+ if ( code === 9 ) {
65+ return 'Invalid Argument ';
66+ }
6167
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+ }
6571
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+ }
7375
74- if ( code === 10 ) {
75- return 'Internal JavaScript Run-Time Failure ';
76- }
76+ if ( code > 128 ) {
77+ return 'Signal Exits ';
78+ }
7779
78- if ( code === 12 ) {
79- return 'Invalid Debug Argument' ;
80- }
80+ return null ;
81+ }
8182
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+ }
8588
86- return null ;
89+ client . config . queue . process ( )
90+ } ) ;
8791 }
8892}
0 commit comments