|
|
|
@ -12,7 +12,7 @@ export function registerExitHandler(callback: () => void) {
|
|
|
|
|
exitHandlers.push(callback); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function exitHandler(options, err) { |
|
|
|
|
function exitHandler(options, err?) { |
|
|
|
|
if(exitHandled) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
@ -24,6 +24,12 @@ function exitHandler(options, err) {
|
|
|
|
|
process.exit(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function catchException(options, err) { |
|
|
|
|
console.log('Server exception:'); |
|
|
|
|
console.log(err); |
|
|
|
|
exitHandler({ exit: true }); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//do something when app is closing
|
|
|
|
|
process.on('exit', exitHandler.bind(null, { cleanup:true })); |
|
|
|
|
|
|
|
|
@ -35,4 +41,4 @@ process.on('SIGUSR1', exitHandler.bind(null, {exit:true}));
|
|
|
|
|
process.on('SIGUSR2', exitHandler.bind(null, { exit:true })); |
|
|
|
|
|
|
|
|
|
//catches uncaught exceptions
|
|
|
|
|
process.on('uncaughtException', exitHandler.bind(null, {exit:true})); |
|
|
|
|
process.on('uncaughtException', catchException.bind(null, { exit:true })); |