Fix duplicated error message when logging UnexpectedStatusException
Not sure what's causing this. (Bluebird?) Also add stack to custom HTTP exceptions.
This commit is contained in:
parent
c0a2ec8a47
commit
3df66ccbe4
2 changed files with 21 additions and 13 deletions
|
@ -14,6 +14,7 @@ Zotero.HTTP = new function() {
|
||||||
this.status = xmlhttp.status;
|
this.status = xmlhttp.status;
|
||||||
this.channel = xmlhttp.channel;
|
this.channel = xmlhttp.channel;
|
||||||
this.message = msg;
|
this.message = msg;
|
||||||
|
this.stack = new Error().stack;
|
||||||
|
|
||||||
// Hide password from debug output
|
// Hide password from debug output
|
||||||
//
|
//
|
||||||
|
@ -40,9 +41,6 @@ Zotero.HTTP = new function() {
|
||||||
this.UnexpectedStatusException.prototype.is5xx = function () {
|
this.UnexpectedStatusException.prototype.is5xx = function () {
|
||||||
return this.status >= 500 && this.status < 600;
|
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
|
* Exception returned if the browser is offline when promise* is used
|
||||||
|
@ -50,19 +48,15 @@ Zotero.HTTP = new function() {
|
||||||
*/
|
*/
|
||||||
this.BrowserOfflineException = function() {
|
this.BrowserOfflineException = function() {
|
||||||
this.message = "XMLHttpRequest could not complete because the browser is offline";
|
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 = Object.create(Error.prototype);
|
||||||
this.BrowserOfflineException.prototype.toString = function() {
|
|
||||||
return this.message;
|
|
||||||
};
|
|
||||||
|
|
||||||
this.TimeoutException = function(ms) {
|
this.TimeoutException = function(ms) {
|
||||||
this.message = "XMLHttpRequest has timed out after " + ms + "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 = Object.create(Error.prototype);
|
||||||
this.TimeoutException.prototype.toString = function() {
|
|
||||||
return this.message;
|
|
||||||
};
|
|
||||||
|
|
||||||
this.promise = function () {
|
this.promise = function () {
|
||||||
Zotero.debug("Zotero.HTTP.promise() is deprecated -- use Zotero.HTTP.request()", 2);
|
Zotero.debug("Zotero.HTTP.promise() is deprecated -- use Zotero.HTTP.request()", 2);
|
||||||
|
|
|
@ -1431,10 +1431,24 @@ Zotero.Utilities = {
|
||||||
header = (obj.name ? obj.name + ' ' : '') + 'Exception';
|
header = (obj.name ? obj.name + ' ' : '') + 'Exception';
|
||||||
}
|
}
|
||||||
|
|
||||||
return header + ': '
|
let msg = (obj.message ? ('' + obj.message).replace(/^/gm, level_padding).trim() : '');
|
||||||
+ (obj.message ? ('' + obj.message).replace(/^/gm, level_padding).trim() : '')
|
if (obj.stack) {
|
||||||
+ '\n\n'
|
let stack = obj.stack.trim().replace(/^(?=.)/gm, level_padding);
|
||||||
+ (obj.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)
|
// Only dump single level for nsIDOMNode objects (including document)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue