From 2652fac24bb533c7829f88fde23d97942088c309 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Mon, 23 Jul 2018 07:04:38 -0400 Subject: [PATCH] Throw translation error on >=400 status code for doGet()/doPost() Previously the handler would be called even on error pages, which often meant that an import translator (e.g., BibTeX) would fail to find anything on the page and the save popup would just close silently. The popup will now show an error message as soon as the error occurs. --- chrome/content/zotero/xpcom/utilities_translate.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/chrome/content/zotero/xpcom/utilities_translate.js b/chrome/content/zotero/xpcom/utilities_translate.js index 9d36220ef0..af489bf59d 100644 --- a/chrome/content/zotero/xpcom/utilities_translate.js +++ b/chrome/content/zotero/xpcom/utilities_translate.js @@ -326,6 +326,11 @@ 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) { + translate.complete(false, `HTTP GET ${url} failed with status code ${xmlhttp.status}`); + return; + } + try { if(processor) { processor(xmlhttp.responseText, xmlhttp, url); @@ -355,6 +360,11 @@ Zotero.Utilities.Translate.prototype.doPost = function(url, body, onDone, header translate.incrementAsyncProcesses("Zotero.Utilities.Translate#doPost"); var xmlhttp = Zotero.HTTP.doPost(url, body, function(xmlhttp) { + if (xmlhttp.status >= 400) { + translate.complete(false, `HTTP POST ${url} failed with status code ${xmlhttp.status}`); + return; + } + try { onDone(xmlhttp.responseText, xmlhttp); translate.decrementAsyncProcesses("Zotero.Utilities.Translate#doPost");