diff --git a/src/ui/public/courier/fetch/request/_error_handler.js b/src/ui/public/courier/fetch/request/_error_handler.js index 85516b5d04d42..b4f8deba1823d 100644 --- a/src/ui/public/courier/fetch/request/_error_handler.js +++ b/src/ui/public/courier/fetch/request/_error_handler.js @@ -14,7 +14,7 @@ define(function (require) { }); if (!myHandlers.length) { - notify.fatal(new Error('unhandled error ' + (error.stack || error.message))); + notify.fatal(new Error(`unhandled courier request error: ${ notify.describeError(error) }`)); } else { myHandlers.forEach(function (handler) { handler.defer.resolve(error); diff --git a/src/ui/public/notify/lib/_format_msg.js b/src/ui/public/notify/lib/_format_msg.js index 87f75e7e37c03..e0458816836d9 100644 --- a/src/ui/public/notify/lib/_format_msg.js +++ b/src/ui/public/notify/lib/_format_msg.js @@ -8,7 +8,7 @@ define(function (require) { * @param {String} from - Prefix for message indicating source (optional) * @returns {string} */ - return function formatMsg(err, from) { + function formatMsg(err, from) { var rtn = ''; if (from) { rtn += from + ': '; @@ -21,9 +21,18 @@ define(function (require) { } else if (esMsg) { rtn += esMsg; } else if (err instanceof Error) { - rtn += err.message; + rtn += formatMsg.describeError(err); } return rtn; }; + + formatMsg.describeError = function (err) { + if (!err) return undefined; + if (err.body && err.body.message) return err.body.message; + if (err.message) return err.message; + return '' + err; + }; + + return formatMsg; }); diff --git a/src/ui/public/notify/notifier.js b/src/ui/public/notify/notifier.js index 66203e35f5c2f..bf9269d683aca 100644 --- a/src/ui/public/notify/notifier.js +++ b/src/ui/public/notify/notifier.js @@ -267,6 +267,8 @@ define(function (require) { }, cb); }; + Notifier.prototype.describeError = formatMsg.describeError; + if (log === _.noop) { Notifier.prototype.log = _.noop; } else {