On 404 from ZFS upload, mark attachment item for upload

This shouldn't happen, but reported here:

https://forums.zotero.org/discussion/64386/5-0-beta-persistent-sync-errors

Possibly the same cause as this:

https://forums.zotero.org/discussion/64438/5-0-beta-persistent-sync-error
This commit is contained in:
Dan Stillman 2017-02-16 20:11:05 -05:00
parent 34c90fd156
commit 058a4b1593
2 changed files with 44 additions and 7 deletions

View file

@ -476,13 +476,14 @@ Zotero.Sync.Storage.Mode.ZFS.prototype = {
);
throw e;
}
// This shouldn't happen, but if it does, mark item for upload and restart sync
else if (req.status == 404) {
Components.utils.reportError("Unexpected status code 404 in upload authorization "
+ "request (" + item.libraryKey + ")");
// TODO: Make an API request to fix this
throw new Error(Zotero.Sync.Storage.defaultError);
Zotero.logError(`Item ${item.libraryID}/${item.key} not found in upload authorization `
+ 'request -- marking for upload');
yield Zotero.Sync.Data.Local.markObjectAsUnsynced(item);
return new Zotero.Sync.Storage.Result({
syncRequired: true
});
}
else if (req.status == 412) {
let version = req.getResponseHeader('Last-Modified-Version');

View file

@ -132,7 +132,7 @@ describe("Zotero.Sync.Storage.Mode.ZFS", function () {
assert.equal(library.storageVersion, library.libraryVersion);
})
it("should ignore a remotely missing file", function* () {
it("should ignore download for a remotely missing file", function* () {
var { engine, client, caller } = yield setup();
var library = Zotero.Libraries.userLibrary;
@ -758,6 +758,42 @@ describe("Zotero.Sync.Storage.Mode.ZFS", function () {
describe("#_processUploadFile()", function () {
it("should handle 404 from upload authorization request", function* () {
var { engine, client, caller } = yield setup();
var zfs = new Zotero.Sync.Storage.Mode.ZFS({
apiClient: client
})
var filePath = OS.Path.join(getTestDataDirectory().path, 'test.png');
var item = yield Zotero.Attachments.importFromFile({ file: filePath });
item.version = 5;
item.synced = true;
yield item.saveTx();
var itemJSON = item.toResponseJSON();
itemJSON.data.mtime = yield item.attachmentModificationTime;
itemJSON.data.md5 = yield item.attachmentHash;
server.respond(function (req) {
if (req.method == "POST"
&& req.url == `${baseURL}users/1/items/${item.key}/file`
&& !req.requestBody.includes('upload=')) {
req.respond(
404,
{
"Last-Modified-Version": 5
},
"Not Found"
);
}
})
var result = yield zfs._processUploadFile({
name: item.libraryKey
});
assert.isTrue(result.syncRequired);
});
it("should handle 412 with matching version and hash matching local file", function* () {
var { engine, client, caller } = yield setup();
var zfs = new Zotero.Sync.Storage.Mode.ZFS({