Resolve ontimeout and onerror
Used 'unresolved' function to resolve the faviconPromise with an empty string
This commit is contained in:
Родитель
6306b80702
Коммит
c61f9307f4
|
@ -21,7 +21,7 @@ const bmsvc = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].getService(Ci.n
|
|||
const ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
|
||||
|
||||
// timeout for fetching favicon
|
||||
var DEFAULT_TIMEOUT = 3000;
|
||||
let DEFAULT_TIMEOUT = 3000;
|
||||
|
||||
/**
|
||||
* Merge obj2 into obj1.
|
||||
|
@ -238,6 +238,9 @@ function propertyComparator(property) {
|
|||
function _getFavicon(faviconURL) {
|
||||
let faviconPromise = Promise.defer();
|
||||
let xhr = new XMLHttpRequest();
|
||||
let unresolved = function() {
|
||||
faviconPromise.resolve("");
|
||||
}
|
||||
xhr.mozBackgroundRequest = true;
|
||||
xhr.onload = function() {
|
||||
if (this.status == 401 || this.status == 404) {
|
||||
|
@ -248,6 +251,8 @@ function _getFavicon(faviconURL) {
|
|||
};
|
||||
xhr.open("get", faviconURL, true);
|
||||
xhr.timeout = DEFAULT_TIMEOUT;
|
||||
xhr.ontimeout = unresolved;
|
||||
xhr.onerror = unresolved;
|
||||
xhr.send();
|
||||
return faviconPromise.promise;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче