[Notifier] added better error descriptions

This commit is contained in:
spalger 2015-12-09 10:06:42 -07:00
parent d054985eed
commit 9efd34bc69
3 changed files with 14 additions and 3 deletions

View file

@ -14,7 +14,7 @@ define(function (require) {
}); });
if (!myHandlers.length) { 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 { } else {
myHandlers.forEach(function (handler) { myHandlers.forEach(function (handler) {
handler.defer.resolve(error); handler.defer.resolve(error);

View file

@ -8,7 +8,7 @@ define(function (require) {
* @param {String} from - Prefix for message indicating source (optional) * @param {String} from - Prefix for message indicating source (optional)
* @returns {string} * @returns {string}
*/ */
return function formatMsg(err, from) { function formatMsg(err, from) {
var rtn = ''; var rtn = '';
if (from) { if (from) {
rtn += from + ': '; rtn += from + ': ';
@ -21,9 +21,18 @@ define(function (require) {
} else if (esMsg) { } else if (esMsg) {
rtn += esMsg; rtn += esMsg;
} else if (err instanceof Error) { } else if (err instanceof Error) {
rtn += err.message; rtn += formatMsg.describeError(err);
} }
return rtn; 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;
}); });

View file

@ -267,6 +267,8 @@ define(function (require) {
}, cb); }, cb);
}; };
Notifier.prototype.describeError = formatMsg.describeError;
if (log === _.noop) { if (log === _.noop) {
Notifier.prototype.log = _.noop; Notifier.prototype.log = _.noop;
} else { } else {