Add error handling to UrlClassifier

This commit is contained in:
Maxim Zhilyaev 2014-05-01 15:09:14 -07:00 коммит произвёл Ed Lee
Родитель 14a803efc9
Коммит 4f62341faa
2 изменённых файлов: 33 добавлений и 23 удалений

Просмотреть файл

@ -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;
},
}

Просмотреть файл

@ -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);
}