From 1e2ad01f999abb0b2991a4050c812ce73f2f2055 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Mon, 21 Jun 2021 04:51:39 -0400 Subject: [PATCH] Zotero.File.download(): Throw error on non-200 response --- chrome/content/zotero/xpcom/file.js | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/chrome/content/zotero/xpcom/file.js b/chrome/content/zotero/xpcom/file.js index 3a97009911..aef260600d 100644 --- a/chrome/content/zotero/xpcom/file.js +++ b/chrome/content/zotero/xpcom/file.js @@ -448,14 +448,34 @@ Zotero.File = new function(){ this.download = Zotero.Promise.coroutine(function* (uri, path) { - Zotero.debug("Saving " + (uri.spec ? uri.spec : uri) - + " to " + (path.pathQueryRef ? path.pathQueryRef : path)); + var uriStr = uri.spec || uri; + + Zotero.debug(`Saving ${uriStr} to ${path.pathQueryRef || path}`); + + if (Zotero.HTTP.browserIsOffline()) { + let msg = `Download failed: ${Zotero.appName} is currently offline`; + Zotero.debug(msg, 2); + throw new Error(msg); + } var deferred = Zotero.Promise.defer(); NetUtil.asyncFetch(uri, function (is, status, request) { if (!Components.isSuccessCode(status)) { Zotero.logError(status); - deferred.reject(new Error("Download failed with status " + status)); + let msg = Zotero.getString('sync.error.checkConnection'); + switch (status) { + case 2152398878: + // TODO: Localize + msg = "Server not found. Check your internet connection." + break; + } + deferred.reject(new Error(msg)); + return; + } + if (request.responseStatus != 200) { + let msg = `Download failed with response code ${request.responseStatus}`; + Zotero.logError(msg); + deferred.reject(new Error(msg)); return; } deferred.resolve(is);