Fix handling of network errors for SingleFile save
This commit is contained in:
parent
20c8cede4d
commit
1c5cefaffd
2 changed files with 44 additions and 5 deletions
|
@ -576,7 +576,7 @@ Zotero.Utilities.Internal = {
|
||||||
xhrRequest.withCredentials = true;
|
xhrRequest.withCredentials = true;
|
||||||
xhrRequest.responseType = "arraybuffer";
|
xhrRequest.responseType = "arraybuffer";
|
||||||
xhrRequest.onerror = (e) => {
|
xhrRequest.onerror = (e) => {
|
||||||
let error = new Error(e.detail);
|
let error = e.detail;
|
||||||
onDone(Components.utils.cloneInto(error, sandbox));
|
onDone(Components.utils.cloneInto(error, sandbox));
|
||||||
};
|
};
|
||||||
xhrRequest.onreadystatechange = () => {
|
xhrRequest.onreadystatechange = () => {
|
||||||
|
@ -591,7 +591,7 @@ Zotero.Utilities.Internal = {
|
||||||
onDone(Components.utils.cloneInto(res, sandbox));
|
onDone(Components.utils.cloneInto(res, sandbox));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
let error = new Error('Bad Status or Length');
|
let error = 'Bad Status or Length';
|
||||||
onDone(Components.utils.cloneInto(error, sandbox));
|
onDone(Components.utils.cloneInto(error, sandbox));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -615,13 +615,13 @@ Zotero.Utilities.Internal = {
|
||||||
catch (error) {
|
catch (error) {
|
||||||
let response = await new Promise((resolve, reject) => {
|
let response = await new Promise((resolve, reject) => {
|
||||||
coFetch(url, (response) => {
|
coFetch(url, (response) => {
|
||||||
if (response.status) {
|
if (typeof response === 'object') {
|
||||||
resolve(response);
|
resolve(response);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Zotero.debug("Error retrieving url: " + url);
|
Zotero.debug("Error retrieving url: " + url);
|
||||||
Zotero.debug(response.message);
|
Zotero.debug(response);
|
||||||
reject();
|
reject(new Error(response));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -424,6 +424,45 @@ describe("Zotero.Attachments", function() {
|
||||||
let expectedContents = await Zotero.File.getBinaryContentsAsync(expectedPath);
|
let expectedContents = await Zotero.File.getBinaryContentsAsync(expectedPath);
|
||||||
assert.equal(contents, expectedContents);
|
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(`<html><head><title>Test</title></head><body><img src="${url}"/>`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
var deferred = Zotero.Promise.defer();
|
||||||
|
win.addEventListener('pageshow', () => deferred.resolve());
|
||||||
|
win.loadURI(testServerPath + "/index.html");
|
||||||
|
await deferred.promise;
|
||||||
|
|
||||||
|
var attachment = await Zotero.Attachments.importFromDocument({
|
||||||
|
document: win.content.document,
|
||||||
|
parentItemID: item.id
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.equal(attachment.getField('url'), testServerPath + "/index.html");
|
||||||
|
|
||||||
|
// Check for embedded files
|
||||||
|
var storageDir = Zotero.Attachments.getStorageDirectory(attachment).path;
|
||||||
|
var file = await attachment.getFilePathAsync();
|
||||||
|
assert.equal(OS.Path.basename(file), 'index.html');
|
||||||
|
assert.isFalse(await OS.File.exists(OS.Path.join(storageDir, 'images', '1.gif')));
|
||||||
|
|
||||||
|
// Check attachment html file contents
|
||||||
|
let path = OS.Path.join(storageDir, 'index.html');
|
||||||
|
assert.isTrue(await OS.File.exists(path));
|
||||||
|
let contents = await Zotero.File.getContentsAsync(path);
|
||||||
|
assert.isTrue(contents.startsWith("<html><!--\n Page saved with SingleFileZ"));
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("#importFromPageData()", function () {
|
describe("#importFromPageData()", function () {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue