- fix issues with errors in async detectCode

This commit is contained in:
Simon Kornblith 2007-03-19 19:21:32 +00:00
parent 2de3ed40c5
commit 5bb324e2eb
3 changed files with 18 additions and 10 deletions

View File

@ -583,7 +583,7 @@ Zotero.OpenURL = new function() {
if(pAu.lastName == au.lastName && if(pAu.lastName == au.lastName &&
(pAu.firstName == au.firstName == "" || (pAu.firstName == au.firstName == "" ||
(pAu.firstName.length >= au.firstName.length && (pAu.firstName.length >= au.firstName.length &&
pAu.substr(0, au.firstName.length) == au.firstName))) { pAu.firstName.substr(0, au.firstName.length) == au.firstName))) {
pushMe = false; pushMe = false;
break; break;
} }

View File

@ -495,7 +495,8 @@ Zotero.Translate.prototype.getTranslators = function() {
// see which translators can translate // see which translators can translate
this._translatorSearch = new Zotero.Translate.TranslatorSearch(this, translators); this._translatorSearch = new Zotero.Translate.TranslatorSearch(this, translators);
Zotero.debug(this._translatorSearch.foundTranslators); // erroring should call complete
this.error = function(value, error) { this._translatorSearch.complete(value, error) };
// return translators if asynchronous // return translators if asynchronous
if(!this._translatorSearch.asyncMode) return this._translatorSearch.foundTranslators; if(!this._translatorSearch.asyncMode) return this._translatorSearch.foundTranslators;
@ -557,6 +558,9 @@ Zotero.Translate.prototype.translate = function() {
throw("cannot translate: no location specified"); throw("cannot translate: no location specified");
} }
// erroring should end
this.error = this._translationComplete;
if(!this._loadTranslator()) { if(!this._loadTranslator()) {
return; return;
} }
@ -885,7 +889,7 @@ Zotero.Translate.prototype._translationComplete = function(returnValue, error) {
if(!returnValue) { if(!returnValue) {
var errorString = this._generateErrorString(error); var errorString = this._generateErrorString(error);
this._debug("Translation using "+this.translator[0].label+" failed: \n"+errorString); this._debug("Translation using "+(this.translator && this.translator[0] && this.translator[0].label ? this.translator[0].label : "no translator")+" failed: \n"+errorString);
if(this.type == "web") { if(this.type == "web") {
// report translation error for webpages // report translation error for webpages
@ -2076,8 +2080,7 @@ Zotero.Translate.TranslatorSearch.prototype.execute = function() {
returnValue = this.translate._sandbox.detectImport(); returnValue = this.translate._sandbox.detectImport();
} }
} catch(e) { } catch(e) {
Zotero.debug(e+' in executing detectCode for '+translator.label); this.complete(returnValue, e);
this.execute();
return; return;
} }
@ -2131,12 +2134,17 @@ Zotero.Translate.TranslatorSearch.prototype.processReturnValue = function(transl
this.foundTranslators.push(translator); this.foundTranslators.push(translator);
} }
Zotero.Translate.TranslatorSearch.prototype.complete = function(returnValue) { Zotero.Translate.TranslatorSearch.prototype.complete = function(returnValue, error) {
// reset done function // reset done function
this.translate._sandbox.Zotero.done = undefined; this.translate._sandbox.Zotero.done = undefined;
this.translate.waitForCompletion = false; this.translate.waitForCompletion = false;
if(returnValue) {
this.processReturnValue(this.currentTranslator, returnValue); this.processReturnValue(this.currentTranslator, returnValue);
} else if(error) {
var errorString = this.translate._generateErrorString(error);
Zotero.debug("detectCode for "+(this.currentTranslator ? this.currentTranslator.label : "no translator")+" failed: \n"+errorString);
}
this.currentTranslator = undefined; this.currentTranslator = undefined;
this.asyncMode = false; this.asyncMode = false;

View File

@ -441,7 +441,7 @@ Zotero.Utilities.Ingester.prototype.processDocuments = function(urls, processor,
if(!exception) { if(!exception) {
var translate = this.translate; var translate = this.translate;
exception = function(e) { exception = function(e) {
translate._translationComplete(false, e); translate.error(false, e);
} }
} }
@ -485,7 +485,7 @@ Zotero.Utilities.Ingester.HTTP.prototype.doGet = function(urls, processor, done)
} }
} }
} catch(e) { } catch(e) {
me.translate._translationComplete(false, e); me.translate.error(false, e);
} }
}); });
} }
@ -503,7 +503,7 @@ Zotero.Utilities.Ingester.HTTP.prototype.doPost = function(url, body, onDone, co
try { try {
onDone(xmlhttp.responseText, xmlhttp); onDone(xmlhttp.responseText, xmlhttp);
} catch(e) { } catch(e) {
translate._translationComplete(false, e); translate.error(false, e);
} }
}, contentType); }, contentType);
} }