diff --git a/chrome/content/zotero/xpcom/utilities_internal.js b/chrome/content/zotero/xpcom/utilities_internal.js index eb8f75f9b3..2359c39ebb 100644 --- a/chrome/content/zotero/xpcom/utilities_internal.js +++ b/chrome/content/zotero/xpcom/utilities_internal.js @@ -576,7 +576,7 @@ Zotero.Utilities.Internal = { xhrRequest.withCredentials = true; xhrRequest.responseType = "arraybuffer"; xhrRequest.onerror = (e) => { - let error = new Error(e.detail); + let error = e.detail; onDone(Components.utils.cloneInto(error, sandbox)); }; xhrRequest.onreadystatechange = () => { @@ -591,7 +591,7 @@ Zotero.Utilities.Internal = { onDone(Components.utils.cloneInto(res, sandbox)); } else { - let error = new Error('Bad Status or Length'); + let error = 'Bad Status or Length'; onDone(Components.utils.cloneInto(error, sandbox)); } } @@ -615,13 +615,13 @@ Zotero.Utilities.Internal = { catch (error) { let response = await new Promise((resolve, reject) => { coFetch(url, (response) => { - if (response.status) { + if (typeof response === 'object') { resolve(response); } else { Zotero.debug("Error retrieving url: " + url); - Zotero.debug(response.message); - reject(); + Zotero.debug(response); + reject(new Error(response)); } }); }); diff --git a/test/tests/attachmentsTest.js b/test/tests/attachmentsTest.js index bf9f0e2025..77d7a9fcab 100644 --- a/test/tests/attachmentsTest.js +++ b/test/tests/attachmentsTest.js @@ -424,6 +424,45 @@ describe("Zotero.Attachments", function() { let expectedContents = await Zotero.File.getBinaryContentsAsync(expectedPath); assert.equal(contents, expectedContents); }); + + it("should save a document with embedded files that throw errors", async function () { + var item = await createDataObject('item'); + + var url = "file://" + OS.Path.join(getTestDataDirectory().path, "snapshot", "foobar.gif"); + httpd.registerPathHandler( + '/index.html', + { + handle: function (request, response) { + response.setStatusLine(null, 200, "OK"); + response.write(`