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:
parent
34c90fd156
commit
058a4b1593
|
@ -476,13 +476,14 @@ Zotero.Sync.Storage.Mode.ZFS.prototype = {
|
||||||
);
|
);
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
// This shouldn't happen, but if it does, mark item for upload and restart sync
|
||||||
else if (req.status == 404) {
|
else if (req.status == 404) {
|
||||||
Components.utils.reportError("Unexpected status code 404 in upload authorization "
|
Zotero.logError(`Item ${item.libraryID}/${item.key} not found in upload authorization `
|
||||||
+ "request (" + item.libraryKey + ")");
|
+ 'request -- marking for upload');
|
||||||
|
yield Zotero.Sync.Data.Local.markObjectAsUnsynced(item);
|
||||||
// TODO: Make an API request to fix this
|
return new Zotero.Sync.Storage.Result({
|
||||||
|
syncRequired: true
|
||||||
throw new Error(Zotero.Sync.Storage.defaultError);
|
});
|
||||||
}
|
}
|
||||||
else if (req.status == 412) {
|
else if (req.status == 412) {
|
||||||
let version = req.getResponseHeader('Last-Modified-Version');
|
let version = req.getResponseHeader('Last-Modified-Version');
|
||||||
|
|
|
@ -132,7 +132,7 @@ describe("Zotero.Sync.Storage.Mode.ZFS", function () {
|
||||||
assert.equal(library.storageVersion, library.libraryVersion);
|
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 { engine, client, caller } = yield setup();
|
||||||
|
|
||||||
var library = Zotero.Libraries.userLibrary;
|
var library = Zotero.Libraries.userLibrary;
|
||||||
|
@ -758,6 +758,42 @@ describe("Zotero.Sync.Storage.Mode.ZFS", function () {
|
||||||
|
|
||||||
|
|
||||||
describe("#_processUploadFile()", 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* () {
|
it("should handle 412 with matching version and hash matching local file", function* () {
|
||||||
var { engine, client, caller } = yield setup();
|
var { engine, client, caller } = yield setup();
|
||||||
var zfs = new Zotero.Sync.Storage.Mode.ZFS({
|
var zfs = new Zotero.Sync.Storage.Mode.ZFS({
|
||||||
|
|
Loading…
Reference in New Issue
Block a user