Fix handling of 413 for over-quota errors
And fix handling of custom error dialog button text/callbacks in general.
This commit is contained in:
parent
098655d913
commit
1c90a77298
|
@ -26,7 +26,11 @@
|
|||
|
||||
Zotero.Error = function (message, error, data) {
|
||||
this.message = message;
|
||||
this.data = data;
|
||||
if (data) {
|
||||
for (let prop in data) {
|
||||
this[prop] = data[prop];
|
||||
}
|
||||
}
|
||||
if (parseInt(error) == error) {
|
||||
this.error = error;
|
||||
}
|
||||
|
|
|
@ -1506,7 +1506,6 @@ Zotero.Sync.Storage.Mode.WebDAV.prototype = {
|
|||
msg,
|
||||
0,
|
||||
{
|
||||
dialogText: msg,
|
||||
dialogButtonText: buttonText,
|
||||
dialogButtonCallback: func
|
||||
}
|
||||
|
@ -1520,7 +1519,6 @@ Zotero.Sync.Storage.Mode.WebDAV.prototype = {
|
|||
msg,
|
||||
0,
|
||||
{
|
||||
dialogText: msg,
|
||||
dialogButtonText: Zotero.getString('sync.storage.error.webdav.loadURL'),
|
||||
dialogButtonCallback: function () {
|
||||
var zp = Zotero.getActiveZoteroPane();
|
||||
|
|
|
@ -583,13 +583,15 @@ Zotero.Sync.Storage.Mode.ZFS.prototype = {
|
|||
}
|
||||
}
|
||||
|
||||
text += "\n\n" + filename + " (" + Math.round(file.fileSize / 1024) + "KB)";
|
||||
var filename = item.attachmentFilename;
|
||||
var fileSize = (yield OS.File.stat(item.getFilePath())).size;
|
||||
|
||||
text += "\n\n" + filename + " (" + Math.round(fileSize / 1024) + "KB)";
|
||||
|
||||
let e = new Zotero.Error(
|
||||
Zotero.getString('sync.storage.error.zfs.fileWouldExceedQuota', filename),
|
||||
text,
|
||||
"ZFS_OVER_QUOTA",
|
||||
{
|
||||
dialogText: text,
|
||||
dialogButtonText: buttonText,
|
||||
dialogButtonCallback: buttonCallback
|
||||
}
|
||||
|
|
|
@ -301,7 +301,6 @@ Zotero.Sync.Server = new function () {
|
|||
msg,
|
||||
0,
|
||||
{
|
||||
dialogText: msg,
|
||||
dialogButtonText: Zotero.getString('pane.items.showItemInLibrary'),
|
||||
dialogButtonCallback: function () {
|
||||
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
|
||||
|
|
|
@ -854,7 +854,6 @@ Zotero.Sync.Runner_Module = function (options = {}) {
|
|||
// TODO: localize (=>done) and combine with below (=>?)
|
||||
var msg = Zotero.getString('sync.error.invalidLogin.text');
|
||||
e.message = msg;
|
||||
e.dialogText = msg;
|
||||
e.dialogButtonText = Zotero.getString('sync.openSyncPreferences');
|
||||
e.dialogButtonCallback = function () {
|
||||
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
|
||||
|
@ -1079,9 +1078,6 @@ Zotero.Sync.Runner_Module = function (options = {}) {
|
|||
|
||||
e.parsed = true;
|
||||
e.errorType = e.errorType ? e.errorType : 'error';
|
||||
if (!e.data) {
|
||||
e.data = {};
|
||||
}
|
||||
|
||||
return e;
|
||||
}
|
||||
|
@ -1159,7 +1155,7 @@ Zotero.Sync.Runner_Module = function (options = {}) {
|
|||
e.dialogButtonText = null;
|
||||
}*/
|
||||
|
||||
if (e.data && e.dialogButtonText !== null) {
|
||||
if (e.dialogButtonText !== null) {
|
||||
if (e.dialogButtonText === undefined) {
|
||||
var buttonText = Zotero.getString('errorReport.reportError');
|
||||
var buttonCallback = function () {
|
||||
|
|
|
@ -380,22 +380,15 @@ Zotero.Utilities.Internal = {
|
|||
.getService(Components.interfaces.nsIPromptService);
|
||||
var message, buttonText, buttonCallback;
|
||||
|
||||
if (e.data) {
|
||||
if (e.data.dialogText) {
|
||||
message = e.data.dialogText;
|
||||
}
|
||||
if (typeof e.data.dialogButtonText != 'undefined') {
|
||||
buttonText = e.data.dialogButtonText;
|
||||
buttonCallback = e.data.dialogButtonCallback;
|
||||
}
|
||||
if (e.dialogButtonText !== undefined) {
|
||||
buttonText = e.dialogButtonText;
|
||||
buttonCallback = e.dialogButtonCallback;
|
||||
}
|
||||
if (!message) {
|
||||
if (e.message) {
|
||||
message = e.message;
|
||||
}
|
||||
else {
|
||||
message = e;
|
||||
}
|
||||
if (e.message) {
|
||||
message = e.message;
|
||||
}
|
||||
else {
|
||||
message = e;
|
||||
}
|
||||
|
||||
if (typeof buttonText == 'undefined') {
|
||||
|
|
|
@ -799,6 +799,25 @@ describe("Zotero.Sync.Runner", function () {
|
|||
});
|
||||
|
||||
|
||||
it("should show a custom button in the error panel", function* () {
|
||||
win = yield loadZoteroPane();
|
||||
var libraryID = Zotero.Libraries.userLibraryID;
|
||||
|
||||
yield runner.sync({
|
||||
background: true
|
||||
});
|
||||
|
||||
var doc = win.document;
|
||||
var errorIcon = doc.getElementById('zotero-tb-sync-error');
|
||||
assert.isFalse(errorIcon.hidden);
|
||||
errorIcon.click();
|
||||
var panel = win.document.getElementById('zotero-sync-error-panel');
|
||||
var buttons = panel.getElementsByTagName('button');
|
||||
assert.lengthOf(buttons, 1);
|
||||
assert.equal(buttons[0].label, Zotero.getString('sync.openSyncPreferences'));
|
||||
});
|
||||
|
||||
|
||||
// TODO: Test multiple long tags and tags across libraries
|
||||
describe("Long Tag Fixer", function () {
|
||||
it("should split a tag", function* () {
|
||||
|
|
|
@ -821,5 +821,42 @@ describe("Zotero.Sync.Storage.Mode.ZFS", function () {
|
|||
assert.isFalse(result.remoteChanges);
|
||||
assert.isTrue(result.syncRequired);
|
||||
})
|
||||
|
||||
it("should handle 413 on quota limit", function* () {
|
||||
var { engine, client, caller } = yield setup();
|
||||
var zfs = new Zotero.Sync.Storage.Mode.ZFS({
|
||||
apiClient: client
|
||||
})
|
||||
|
||||
var file = getTestDataDirectory();
|
||||
file.append('test.png');
|
||||
var item = yield Zotero.Attachments.importFromFile({ file });
|
||||
item.version = 5;
|
||||
item.synced = true;
|
||||
yield item.saveTx();
|
||||
|
||||
server.respond(function (req) {
|
||||
if (req.method == "POST"
|
||||
&& req.url == `${baseURL}users/1/items/${item.key}/file`
|
||||
&& req.requestBody.indexOf('upload=') == -1
|
||||
&& req.requestHeaders["If-None-Match"] == "*") {
|
||||
req.respond(
|
||||
413,
|
||||
{
|
||||
"Content-Type": "application/json",
|
||||
"Last-Modified-Version": 10
|
||||
},
|
||||
"File would exceed quota (299.7 + 0.5 > 300)"
|
||||
);
|
||||
}
|
||||
})
|
||||
|
||||
var e = yield getPromiseError(zfs._processUploadFile({
|
||||
name: item.libraryKey
|
||||
}));
|
||||
assert.ok(e);
|
||||
assert.equal(e.errorType, 'warning');
|
||||
assert.include(e.message, 'would exceed your');
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue
Block a user