diff --git a/chrome/content/zotero/xpcom/error.js b/chrome/content/zotero/xpcom/error.js index d6932e4f9..69090c732 100644 --- a/chrome/content/zotero/xpcom/error.js +++ b/chrome/content/zotero/xpcom/error.js @@ -47,6 +47,7 @@ Zotero.Error.ERROR_ZFS_OVER_QUOTA = 5; Zotero.Error.ERROR_ZFS_UPLOAD_QUEUE_LIMIT = 6; Zotero.Error.ERROR_ZFS_FILE_EDITING_DENIED = 7; Zotero.Error.ERROR_INVALID_ITEM_TYPE = 8; +Zotero.Error.ERROR_USER_NOT_AVAILABLE = 9; //Zotero.Error.ERROR_SYNC_EMPTY_RESPONSE_FROM_SERVER = 6; //Zotero.Error.ERROR_SYNC_INVALID_RESPONSE_FROM_SERVER = 7; diff --git a/chrome/content/zotero/xpcom/uri.js b/chrome/content/zotero/xpcom/uri.js index ed87f70fe..270b2515f 100644 --- a/chrome/content/zotero/xpcom/uri.js +++ b/chrome/content/zotero/xpcom/uri.js @@ -73,7 +73,15 @@ Zotero.URI = new function () { this.getLibraryURI = function (libraryID) { - var path = this.getLibraryPath(libraryID); + try { + var path = this.getLibraryPath(libraryID); + } + catch (e) { + if (e.error == Zotero.Error.ERROR_USER_NOT_AVAILABLE) { + return this.getCurrentUserURI(); + } + throw e; + } return _baseURI + path; } @@ -89,7 +97,7 @@ Zotero.URI = new function () { case 'publications': var id = Zotero.Users.getCurrentUserID(); if (!id) { - throw new Exception("User id not available in Zotero.URI.getLibraryPath()"); + throw new Zotero.Error("User id not available", "USER_NOT_AVAILABLE"); } if (libraryType == 'publications') { @@ -113,12 +121,7 @@ Zotero.URI = new function () { * Return URI of item, which might be a local URI if user hasn't synced */ this.getItemURI = function (item) { - if (item.libraryID) { - var baseURI = this.getLibraryURI(item.libraryID); - } - else { - var baseURI = this.getCurrentUserURI(); - } + var baseURI = this.getLibraryURI(item.libraryID); return baseURI + "/items/" + item.key; } @@ -135,12 +138,7 @@ Zotero.URI = new function () { * Return URI of collection, which might be a local URI if user hasn't synced */ this.getCollectionURI = function (collection) { - if (collection.libraryID) { - var baseURI = this.getLibraryURI(collection.libraryID); - } - else { - var baseURI = this.getCurrentUserURI(); - } + var baseURI = this.getLibraryURI(collection.libraryID); return baseURI + "/collections/" + collection.key; }