Add error handling to UrlClassifier
This commit is contained in:
Родитель
14a803efc9
Коммит
4f62341faa
|
@ -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);
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче