Created
August 25, 2020 08:10
-
-
Save rgabaydullov/04937d5429fb49bc7ce29b00dea2ee2b to your computer and use it in GitHub Desktop.
NodeJS error handling example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const uncaughtExceptionHandler = (app) => { | |
/* Считаем, что все middleware функции подключаются в качестве модулей */ | |
process.on('error', middlewareErrorHandler); | |
process.on('uncaughtException', middlewareExceptionHandler); | |
/* В данном случае подразумеваем, что наше приложение может обслуживать | |
несколько микросервисов по типу app, поэтому ловим все ошибки в сервисе process */ | |
app | |
.on('error', middlewareErrorHandler); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment