diff --git a/lib/UrlClassifier.js b/lib/UrlClassifier.js index 5da194f..17d25b5 100644 --- a/lib/UrlClassifier.js +++ b/lib/UrlClassifier.js @@ -79,30 +79,33 @@ UrlClassifier.prototype = { return this._deferred.promise; } - this._deferred = Promise.defer(); + let deferred = this._deferred = Promise.defer(); this._results = {}; - - // submit url+title to workers - let url = url; - let title = title || ""; - let uri = NetUtil.newURI(url); - let host = getPlacesHostForURI(uri); - let message = {}; - message.message = "getInterestsForDocument"; - message.url = url; - message.title = title; - message.host = host; - message.path = uri["path"]; - message.tld = getBaseDomain(host); - message.metaData = {}; - message.language = "en"; - message.messageId = "classifyUrl"; - this._expectedResponses = this._workers.length; - this._workers.forEach(worker => { - this._callMatchingWorker(worker, message); - }); - - return this._deferred.promise; + try { + // submit url+title to workers + let title = title || ""; + let uri = NetUtil.newURI(url); + let host = getPlacesHostForURI(uri); + let message = {}; + message.message = "getInterestsForDocument"; + message.url = url; + message.title = title; + message.host = host; + message.path = uri["path"]; + message.tld = getBaseDomain(host); + message.metaData = {}; + message.language = "en"; + message.messageId = "classifyUrl"; + this._expectedResponses = this._workers.length; + this._workers.forEach(worker => { + this._callMatchingWorker(worker, message); + }); + } + catch (e) { + this._deferred = null; + deferred.reject(e); + } + return deferred.promise; }, } diff --git a/test/test-UrlClassifier.js b/test/test-UrlClassifier.js index 481285b..d355947 100644 --- a/test/test-UrlClassifier.js +++ b/test/test-UrlClassifier.js @@ -33,6 +33,13 @@ exports["test url classifier"] = function test_UrlClassifier(assert, done) { {"type":"combined","interests":["Autos"]}, {"type":"keywords","interests":[]} ]); + // test for an error + yield urlClassifier.classifyPage("not a url").then(result => { + assert.ok(false); + }, + error => { + assert.ok(true); + }); }).then(done); }