From bd11fd723434d3591de2214aa886418e03012c10 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 | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/chrome/content/zotero/xpcom/http.js b/chrome/content/zotero/xpcom/http.js index ed973a9ffc..374f88766d 100644 --- a/chrome/content/zotero/xpcom/http.js +++ b/chrome/content/zotero/xpcom/http.js @@ -677,11 +677,16 @@ Zotero.HTTP = new function() { noMock: true } ); - var bytes = new Uint8Array(await req.response.arrayBuffer()); - await IOUtils.write(path, bytes); - var byteLength = bytes.byteLength; - - Zotero.debug(`Saved file to ${path} (${byteLength} byte${byteLength != 1 ? 's' : ''})`); + if (req.status >= 200 && req.status < 300) { + let bytes = new Uint8Array(await req.response.arrayBuffer()); + await IOUtils.write(path, bytes); + let byteLength = bytes.byteLength; + Zotero.debug(`Saved file to ${path} (${byteLength} byte${byteLength != 1 ? 's' : ''})`); + } + // Only relevant if status is in successCodes + else { + Zotero.debug("Not saving file for non-2xx response code"); + } return req; };