Skip to content

Instantly share code, notes, and snippets.

@rgabaydullov
Created August 25, 2020 08:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rgabaydullov/04937d5429fb49bc7ce29b00dea2ee2b to your computer and use it in GitHub Desktop.
Save rgabaydullov/04937d5429fb49bc7ce29b00dea2ee2b to your computer and use it in GitHub Desktop.
NodeJS error handling example
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