@@ -25,7 +25,6 @@ import { fetchAbi, getHeadBlockNum } from './chain-api';
2525
2626const logger = getLogger ( 'ship-reader-wrapper' ) ;
2727const signal_traps = [ 'SIGTERM' , 'SIGINT' , 'SIGUSR2' ] ;
28- const error_types = [ 'unhandledRejection' , 'uncaughtException' ] ;
2928
3029export class ShipReaderWrapper {
3130 config : ShipReaderWrapperConfig = undefined ;
@@ -46,9 +45,10 @@ export class ShipReaderWrapper {
4645 } ) ;
4746
4847 // handle unexpected error
49- error_types . forEach ( type => {
50- this . handleEvent ( type ) ;
51- } ) ;
48+ process . on ( 'unhandledRejection' , reason =>
49+ this . sendEventAndEndProcess ( 'unhandledRejection' , reason ) ,
50+ ) ;
51+ process . on ( 'uncaughtException' , err => this . sendEventAndEndProcess ( 'uncaughtException' , err ) ) ;
5252 }
5353
5454 /**
@@ -389,7 +389,12 @@ export class ShipReaderWrapper {
389389 resetEvent && ( await this . kafka_wrapper . sendEvent ( resetEvent , 'reset_event' ) ) ;
390390 await this . gracefulShutdown ( ) ;
391391 } finally {
392- process . kill ( process . pid , type ) ;
392+ const isSignal = [ 'SIGTERM' , 'SIGINT' , 'SIGUSR2' ] . includes ( type ) ;
393+ if ( isSignal ) {
394+ process . kill ( process . pid , type as NodeJS . Signals ) ;
395+ } else {
396+ process . exit ( 1 ) ;
397+ }
393398 }
394399 }
395400
0 commit comments