Fail rather than hang sync on S3 upload error

This commit is contained in:
Dan Stillman 2014-03-18 16:57:12 -04:00
parent bfdc9cf5fc
commit fbf2764ef8

View file

@ -492,54 +492,56 @@ Zotero.Sync.Storage.ZFS = (function () {
function onUploadComplete(httpRequest, status, response, data) { function onUploadComplete(httpRequest, status, response, data) {
var request = data.request; return Q.try(function () {
var item = data.item; var request = data.request;
var uploadKey = data.uploadKey; var item = data.item;
var uploadKey = data.uploadKey;
Zotero.debug("Upload of attachment " + item.key
+ " finished with status code " + status);
Zotero.debug(response);
switch (status) {
case 201:
break;
case 500: Zotero.debug("Upload of attachment " + item.key
throw new Error("File upload failed. Please try again."); + " finished with status code " + status);
default: Zotero.debug(response);
var msg = "Unexpected file upload status " + status
+ " in Zotero.Sync.Storage.ZFS.onUploadComplete()" switch (status) {
+ " (" + Zotero.Items.getLibraryKeyHash(item) + ")"; case 201:
Zotero.debug(msg, 1); break;
Components.utils.reportError(msg);
Components.utils.reportError(response); case 500:
throw new Error(Zotero.Sync.Storage.defaultError); throw new Error("File upload failed. Please try again.");
}
default:
var uri = getItemURI(item); var msg = "Unexpected file upload status " + status
var body = "update=" + uploadKey + "&mtime=" + item.attachmentModificationTime; + " in Zotero.Sync.Storage.ZFS.onUploadComplete()"
+ " (" + Zotero.Items.getLibraryKeyHash(item) + ")";
// Register upload on server Zotero.debug(msg, 1);
return Zotero.HTTP.promise("POST", uri, { body: body, headers: _headers, successCodes: [204] }) Components.utils.reportError(msg);
.then(function (req) { Components.utils.reportError(response);
updateItemFileInfo(item); throw new Error(Zotero.Sync.Storage.defaultError);
return { }
localChanges: true,
remoteChanges: true var uri = getItemURI(item);
}; var body = "update=" + uploadKey + "&mtime=" + item.attachmentModificationTime;
})
.fail(function (e) { // Register upload on server
var msg = "Unexpected file registration status " + e.status return Zotero.HTTP.promise("POST", uri, { body: body, headers: _headers, successCodes: [204] })
+ " (" + Zotero.Items.getLibraryKeyHash(item) + ")"; .then(function (req) {
Zotero.debug(msg, 1); updateItemFileInfo(item);
Zotero.debug(e.xmlhttp.responseText); return {
Zotero.debug(e.xmlhttp.getAllResponseHeaders()); localChanges: true,
Components.utils.reportError(msg); remoteChanges: true
Components.utils.reportError(e.xmlhttp.responseText); };
throw new Error(Zotero.Sync.Storage.defaultError); })
}); .fail(function (e) {
var msg = "Unexpected file registration status " + e.status
+ " (" + Zotero.Items.getLibraryKeyHash(item) + ")";
Zotero.debug(msg, 1);
Zotero.debug(e.xmlhttp.responseText);
Zotero.debug(e.xmlhttp.getAllResponseHeaders());
Components.utils.reportError(msg);
Components.utils.reportError(e.xmlhttp.responseText);
throw new Error(Zotero.Sync.Storage.defaultError);
});
});
} }