www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README | LICENSE

commit ec5e20659b985049327a59e5c03d10bf5c996e10
parent 426ac172ff8972af9a0061ba4cdd4cdbdddb1887
Author: Simon Kornblith <simon@simonster.com>
Date:   Sun,  7 Jun 2015 17:20:47 -0400

Improve error handling for attachment saving

Diffstat:
Mchrome/content/zotero/xpcom/attachments.js | 24+++++++++++-------------
1 file changed, 11 insertions(+), 13 deletions(-)

diff --git a/chrome/content/zotero/xpcom/attachments.js b/chrome/content/zotero/xpcom/attachments.js @@ -312,26 +312,24 @@ Zotero.Attachments = new function(){ // Save to temp dir var deferred = Zotero.Promise.defer(); wbp.progressListener = new Zotero.WebProgressFinishListener(function() { - Zotero.File.getSample(tmpFile) - .then(function (sample) { - if (contentType == 'application/pdf' && - Zotero.MIME.sniffForMIMEType(sample) != 'application/pdf') { - let errString = "Downloaded PDF did not have MIME type " - + "'application/pdf' in Attachments.importFromURL()"; - Zotero.debug(errString, 2); - Zotero.debug(sample, 3); - deferred.reject(new Error(errString)); - } else { - deferred.resolve(); - } - }); + deferred.resolve(); }); var nsIURL = Components.classes["@mozilla.org/network/standard-url;1"] .createInstance(Components.interfaces.nsIURL); nsIURL.spec = url; Zotero.Utilities.Internal.saveURI(wbp, nsIURL, tmpFile); + yield deferred.promise; + let sample = yield Zotero.File.getSample(tmpFile); + if (contentType == 'application/pdf' && + Zotero.MIME.sniffForMIMEType(sample) != 'application/pdf') { + let errString = "Downloaded PDF did not have MIME type " + + "'application/pdf' in Attachments.importFromURL()"; + Zotero.debug(errString, 2); + Zotero.debug(sample, 3); + throw(new Error(errString)); + } // Create DB item var attachmentItem;