import type { Logger } from './types.h' ; const SIGNALS = [ 'SIGINT' , 'SIGTERM' , 'SIGQUIT' , 'uncaughtException' ] as const ; export const globalErrorHandler = ( logger = console ) => { const handler = ( signal , err ) => { logger . error ( { event : `Shutdown:platform:server:${ signal }` , error : err instanceof Error ? err : new Error ( err ) , } ) ; process . exit ( ) ; } ; SIGNALS . forEach ( ( signal ) => { process . once ( signal , ( err ) => { if ( process . listenerCount ( signal ) > 0 ) { logger . warn ( `Found other handlers for '${ signal }', let them perform their job` ) ; process . on ( signal , handler . bind ( null , signal ) ) ; } else { handler ( signal , err ) ; } } ) ; } ) ; } ; export const unhandledRejectionHandler = ( logger = console ) => { process . on ( 'unhandledRejection' , ( error ) => { logger . error ( { event : 'unhandled:reject:promise' , error } ) ; } ) ; } ;