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) {
|
Zotero.Error = function (message, error, data) {
|
||||||
this.message = message;
|
this.message = message;
|
||||||
this.data = data;
|
if (data) {
|
||||||
|
for (let prop in data) {
|
||||||
|
this[prop] = data[prop];
|
||||||
|
}
|
||||||
|
}
|
||||||
if (parseInt(error) == error) {
|
if (parseInt(error) == error) {
|
||||||
this.error = error;
|
this.error = error;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1506,7 +1506,6 @@ Zotero.Sync.Storage.Mode.WebDAV.prototype = {
|
||||||
msg,
|
msg,
|
||||||
0,
|
0,
|
||||||
{
|
{
|
||||||
dialogText: msg,
|
|
||||||
dialogButtonText: buttonText,
|
dialogButtonText: buttonText,
|
||||||
dialogButtonCallback: func
|
dialogButtonCallback: func
|
||||||
}
|
}
|
||||||
|
@ -1520,7 +1519,6 @@ Zotero.Sync.Storage.Mode.WebDAV.prototype = {
|
||||||
msg,
|
msg,
|
||||||
0,
|
0,
|
||||||
{
|
{
|
||||||
dialogText: msg,
|
|
||||||
dialogButtonText: Zotero.getString('sync.storage.error.webdav.loadURL'),
|
dialogButtonText: Zotero.getString('sync.storage.error.webdav.loadURL'),
|
||||||
dialogButtonCallback: function () {
|
dialogButtonCallback: function () {
|
||||||
var zp = Zotero.getActiveZoteroPane();
|
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(
|
let e = new Zotero.Error(
|
||||||
Zotero.getString('sync.storage.error.zfs.fileWouldExceedQuota', filename),
|
text,
|
||||||
"ZFS_OVER_QUOTA",
|
"ZFS_OVER_QUOTA",
|
||||||
{
|
{
|
||||||
dialogText: text,
|
|
||||||
dialogButtonText: buttonText,
|
dialogButtonText: buttonText,
|
||||||
dialogButtonCallback: buttonCallback
|
dialogButtonCallback: buttonCallback
|
||||||
}
|
}
|
||||||
|
|
|
@ -301,7 +301,6 @@ Zotero.Sync.Server = new function () {
|
||||||
msg,
|
msg,
|
||||||
0,
|
0,
|
||||||
{
|
{
|
||||||
dialogText: msg,
|
|
||||||
dialogButtonText: Zotero.getString('pane.items.showItemInLibrary'),
|
dialogButtonText: Zotero.getString('pane.items.showItemInLibrary'),
|
||||||
dialogButtonCallback: function () {
|
dialogButtonCallback: function () {
|
||||||
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
|
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 (=>?)
|
// TODO: localize (=>done) and combine with below (=>?)
|
||||||
var msg = Zotero.getString('sync.error.invalidLogin.text');
|
var msg = Zotero.getString('sync.error.invalidLogin.text');
|
||||||
e.message = msg;
|
e.message = msg;
|
||||||
e.dialogText = msg;
|
|
||||||
e.dialogButtonText = Zotero.getString('sync.openSyncPreferences');
|
e.dialogButtonText = Zotero.getString('sync.openSyncPreferences');
|
||||||
e.dialogButtonCallback = function () {
|
e.dialogButtonCallback = function () {
|
||||||
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
|
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
|
||||||
|
@ -1079,9 +1078,6 @@ Zotero.Sync.Runner_Module = function (options = {}) {
|
||||||
|
|
||||||
e.parsed = true;
|
e.parsed = true;
|
||||||
e.errorType = e.errorType ? e.errorType : 'error';
|
e.errorType = e.errorType ? e.errorType : 'error';
|
||||||
if (!e.data) {
|
|
||||||
e.data = {};
|
|
||||||
}
|
|
||||||
|
|
||||||
return e;
|
return e;
|
||||||
}
|
}
|
||||||
|
@ -1159,7 +1155,7 @@ Zotero.Sync.Runner_Module = function (options = {}) {
|
||||||
e.dialogButtonText = null;
|
e.dialogButtonText = null;
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
if (e.data && e.dialogButtonText !== null) {
|
if (e.dialogButtonText !== null) {
|
||||||
if (e.dialogButtonText === undefined) {
|
if (e.dialogButtonText === undefined) {
|
||||||
var buttonText = Zotero.getString('errorReport.reportError');
|
var buttonText = Zotero.getString('errorReport.reportError');
|
||||||
var buttonCallback = function () {
|
var buttonCallback = function () {
|
||||||
|
|
|
@ -380,23 +380,16 @@ Zotero.Utilities.Internal = {
|
||||||
.getService(Components.interfaces.nsIPromptService);
|
.getService(Components.interfaces.nsIPromptService);
|
||||||
var message, buttonText, buttonCallback;
|
var message, buttonText, buttonCallback;
|
||||||
|
|
||||||
if (e.data) {
|
if (e.dialogButtonText !== undefined) {
|
||||||
if (e.data.dialogText) {
|
buttonText = e.dialogButtonText;
|
||||||
message = e.data.dialogText;
|
buttonCallback = e.dialogButtonCallback;
|
||||||
}
|
}
|
||||||
if (typeof e.data.dialogButtonText != 'undefined') {
|
|
||||||
buttonText = e.data.dialogButtonText;
|
|
||||||
buttonCallback = e.data.dialogButtonCallback;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!message) {
|
|
||||||
if (e.message) {
|
if (e.message) {
|
||||||
message = e.message;
|
message = e.message;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
message = e;
|
message = e;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof buttonText == 'undefined') {
|
if (typeof buttonText == 'undefined') {
|
||||||
buttonText = Zotero.getString('errorReport.reportError');
|
buttonText = Zotero.getString('errorReport.reportError');
|
||||||
|
|
|
@ -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
|
// TODO: Test multiple long tags and tags across libraries
|
||||||
describe("Long Tag Fixer", function () {
|
describe("Long Tag Fixer", function () {
|
||||||
it("should split a tag", function* () {
|
it("should split a tag", function* () {
|
||||||
|
|
|
@ -821,5 +821,42 @@ describe("Zotero.Sync.Storage.Mode.ZFS", function () {
|
||||||
assert.isFalse(result.remoteChanges);
|
assert.isFalse(result.remoteChanges);
|
||||||
assert.isTrue(result.syncRequired);
|
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