From a370ec8979b73d6366ef25beb86f211d362fa512 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Thu, 24 Jul 2025 01:08:20 -0400 Subject: [PATCH] HTTP.download(): Don't save file for non-2xx response --- chrome/content/zotero/xpcom/http.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/chrome/content/zotero/xpcom/http.js b/chrome/content/zotero/xpcom/http.js index 4ff8c41f8a..91934b4eeb 100644 --- a/chrome/content/zotero/xpcom/http.js +++ b/chrome/content/zotero/xpcom/http.js @@ -677,8 +677,14 @@ Zotero.HTTP = new function() { noMock: true } ); - var bytes = await IOUtils.write(path, await req.response.bytes()); - Zotero.debug(`Saved file to ${path} (${bytes} byte${bytes != 1 ? 's' : ''})`); + if (req.status >= 200 && req.status < 300) { + var bytes = await IOUtils.write(path, await req.response.bytes()); + Zotero.debug(`Saved file to ${path} (${bytes} byte${bytes != 1 ? 's' : ''})`); + } + // Only relevant if status is in successCodes + else { + Zotero.debug("Not saving file for non-2xx response code"); + } return req; };