www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README | LICENSE

commit 3df66ccbe47692c3250401af2ed2794d40e726c6
parent c0a2ec8a47abbb745b289f52a4ee58570106be99
Author: Dan Stillman <dstillman@zotero.org>
Date:   Fri,  7 Apr 2017 22:32:02 -0400

Fix duplicated error message when logging UnexpectedStatusException

Not sure what's causing this. (Bluebird?)

Also add stack to custom HTTP exceptions.

Diffstat:
Mchrome/content/zotero/xpcom/http.js | 12+++---------
Mchrome/content/zotero/xpcom/utilities.js | 22++++++++++++++++++----
2 files changed, 21 insertions(+), 13 deletions(-)

diff --git a/chrome/content/zotero/xpcom/http.js b/chrome/content/zotero/xpcom/http.js @@ -14,6 +14,7 @@ Zotero.HTTP = new function() { this.status = xmlhttp.status; this.channel = xmlhttp.channel; this.message = msg; + this.stack = new Error().stack; // Hide password from debug output // @@ -40,9 +41,6 @@ Zotero.HTTP = new function() { this.UnexpectedStatusException.prototype.is5xx = function () { return this.status >= 500 && this.status < 600; } - this.UnexpectedStatusException.prototype.toString = function() { - return this.message; - }; /** * Exception returned if the browser is offline when promise* is used @@ -50,19 +48,15 @@ Zotero.HTTP = new function() { */ this.BrowserOfflineException = function() { this.message = "XMLHttpRequest could not complete because the browser is offline"; + this.stack = new Error().stack; }; this.BrowserOfflineException.prototype = Object.create(Error.prototype); - this.BrowserOfflineException.prototype.toString = function() { - return this.message; - }; this.TimeoutException = function(ms) { this.message = "XMLHttpRequest has timed out after " + ms + "ms"; + this.stack = new Error().stack; }; this.TimeoutException.prototype = Object.create(Error.prototype); - this.TimeoutException.prototype.toString = function() { - return this.message; - }; this.promise = function () { Zotero.debug("Zotero.HTTP.promise() is deprecated -- use Zotero.HTTP.request()", 2); diff --git a/chrome/content/zotero/xpcom/utilities.js b/chrome/content/zotero/xpcom/utilities.js @@ -1431,10 +1431,24 @@ Zotero.Utilities = { header = (obj.name ? obj.name + ' ' : '') + 'Exception'; } - return header + ': ' - + (obj.message ? ('' + obj.message).replace(/^/gm, level_padding).trim() : '') - + '\n\n' - + (obj.stack ? obj.stack.trim().replace(/^(?=.)/gm, level_padding) : ''); + let msg = (obj.message ? ('' + obj.message).replace(/^/gm, level_padding).trim() : ''); + if (obj.stack) { + let stack = obj.stack.trim().replace(/^(?=.)/gm, level_padding); + + msg += '\n\n'; + + // At least with Zotero.HTTP.UnexpectedStatusException, the stack contains "Error:" + // and the message in addition to the trace. I'm not sure what's causing that + // (Bluebird?), but fix it here. + if (obj.stack.startsWith('Error:')) { + msg += obj.stack.replace('Error: ' + obj.message + '\n', ''); + } + else { + msg += stack; + } + } + + return header + ': ' + msg; } // Only dump single level for nsIDOMNode objects (including document)