From 09788eb0dd891647a08c884aaab9c30b9f549c07 Mon Sep 17 00:00:00 2001 From: jonyrock-back <58978975+jonyrock-back@users.noreply.github.com> Date: Tue, 18 Feb 2020 13:24:04 +0300 Subject: [PATCH] correct error handling in exitHandler #853 (#854) --- server/src/services/process_service.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/server/src/services/process_service.ts b/server/src/services/process_service.ts index b3e882e..bd4e3e9 100644 --- a/server/src/services/process_service.ts +++ b/server/src/services/process_service.ts @@ -1,4 +1,4 @@ - +import * as config from '../config'; var exitHandlers: (() => void)[] = []; var exitHandled = false; @@ -18,9 +18,16 @@ function exitHandler(options: any, err?: any) { } exitHandled = true; for(let i = 0; i < exitHandlers.length; i++) { - exitHandlers[i](); + try { + exitHandlers[i](); + } catch(e) { + console.error('Got error during exit: ' + e); + if(!config.PRODUCTION_MODE && e instanceof Error) { + console.error(e.stack); + } + } } - console.log('process exit'); + console.log('process exited successfully'); process.exit(); }