From 0be3f062e45526463c72738a19f1d92e083fbdbb Mon Sep 17 00:00:00 2001 From: Yoni Goldberg Date: Tue, 31 Oct 2017 18:38:12 +0200 Subject: [PATCH] Update catchunhandledpromiserejection.md --- sections/errorhandling/catchunhandledpromiserejection.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sections/errorhandling/catchunhandledpromiserejection.md b/sections/errorhandling/catchunhandledpromiserejection.md index bed9acba..94dc9e7d 100644 --- a/sections/errorhandling/catchunhandledpromiserejection.md +++ b/sections/errorhandling/catchunhandledpromiserejection.md @@ -4,11 +4,11 @@ ### One Paragraph Explainer -Typically, most of modern Node.JS/Express application code runs within promises – whether within the .then handler, a function callback or in a catch block. Suprisingly, unless a developer remembered to add a .catch clause, errors thrown at these places disappear without leaving any trace(!). They will not get caught even by app.uncaughtException. The straighforward solution is to never forget adding .catch clause within each promise chain call and redirect to a centralized error handler. However building your error handling strategy only on developer’s discpline is somewhat fragile. Consequently, it’s highly recommended using a graceful fallback and subscribe to process.on(‘unhandledRejection’, callback) – this will ensure that any promise error, if not handled locally, will get its treatment. +Typically, most of modern Node.JS/Express application code runs within promises – whether within the .then handler, a function callback or in a catch block. Suprisingly, unless a developer remembered to add a .catch clause, errors thrown at these places disappear, even not by app.uncaughtException. Recent versions of Node added a warning message when an unhandled rejection pops, though this might help to notice when things go wrong but it's obviously not a proper error handling. The straighforward solution is to never forget adding .catch clause within each promise chain call and redirect to a centralized error handler. However building your error handling strategy only on developer’s discpline is somewhat fragile. Consequently, it’s highly recommended using a graceful fallback and subscribe to process.on(‘unhandledRejection’, callback) – this will ensure that any promise error, if not handled locally, will get its treatment.

-### Code example: Shockingly, these errors will leave no trace +### Code example: these errors will not get caught by any error handler (except unhandledRejection) ```javascript DAL.getUserById(1).then((johnSnow) =>