diff --git a/chrome/content/zotero/xpcom/utilities_translate.js b/chrome/content/zotero/xpcom/utilities_translate.js index bc49373b3c..577bfa87c9 100644 --- a/chrome/content/zotero/xpcom/utilities_translate.js +++ b/chrome/content/zotero/xpcom/utilities_translate.js @@ -308,9 +308,11 @@ Zotero.Utilities.Translate.prototype.processDocuments = async function (urls, pr * @param {Function} done Callback to be executed after all documents have been loaded * @param {String} responseCharset Character set to force on the response * @param {Object} requestHeaders HTTP headers to include with request +* @param {Number[]} successCodes - HTTP status codes that are considered +* successful, or FALSE to allow all * @return {Boolean} True if the request was sent, or false if the browser is offline */ -Zotero.Utilities.Translate.prototype.doGet = function(urls, processor, done, responseCharset, requestHeaders) { +Zotero.Utilities.Translate.prototype.doGet = function(urls, processor, done, responseCharset, requestHeaders, successCodes) { var callAgain = false, me = this, translate = this._translate; @@ -326,7 +328,16 @@ Zotero.Utilities.Translate.prototype.doGet = function(urls, processor, done, res translate.incrementAsyncProcesses("Zotero.Utilities.Translate#doGet"); var xmlhttp = Zotero.HTTP.doGet(url, function(xmlhttp) { - if (xmlhttp.status >= 400 || !xmlhttp.status) { + if (successCodes) { + var success = successCodes.includes(xmlhttp.status); + } + else if (successCodes === false) { + var success = true; + } + else { + var success = xmlhttp.status >= 200 && xmlhttp.status < 400; + } + if (!success) { translate.complete(false, `HTTP GET ${url} failed with status code ${xmlhttp.status}`); return; } @@ -354,13 +365,22 @@ Zotero.Utilities.Translate.prototype.doGet = function(urls, processor, done, res * Already documented in Zotero.HTTP * @ignore */ -Zotero.Utilities.Translate.prototype.doPost = function(url, body, onDone, headers, responseCharset) { +Zotero.Utilities.Translate.prototype.doPost = function(url, body, onDone, headers, responseCharset, successCodes) { var translate = this._translate; url = translate.resolveURL(url); translate.incrementAsyncProcesses("Zotero.Utilities.Translate#doPost"); var xmlhttp = Zotero.HTTP.doPost(url, body, function(xmlhttp) { - if (xmlhttp.status >= 400 || !xmlhttp.status) { + if (successCodes) { + var success = successCodes.includes(xmlhttp.status); + } + else if (successCodes === false) { + var success = true; + } + else { + var success = xmlhttp.status >= 200 && xmlhttp.status < 400; + } + if (!success) { translate.complete(false, `HTTP POST ${url} failed with status code ${xmlhttp.status}`); return; }