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.
This commit is contained in:
Dan Stillman 2018-07-23 07:04:38 -04:00
parent 85667429a8
commit 2652fac24b

View file

@ -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");