Give more info when a ZIM file is not found in unit tests.

Now it gives an error in the console log.
Fixes #234
Also replace this.* by xhr.* to be consistent in the code style
This commit is contained in:
Mossroy 2017-06-19 22:21:21 +02:00
parent 165ae7a8bd
commit 3a166b8ed4

View File

@ -36,22 +36,26 @@ define(['jquery', 'zimArchive', 'zimDirEntry', 'util', 'utf8'],
return new Promise(function (resolve, reject) {
var xhr = new XMLHttpRequest();
xhr.open('GET', url);
xhr.onload = function () {
if ((this.status >= 200 && this.status < 300) || xhr.status == 0 ) {
xhr.onreadystatechange = function () {
if (xhr.readyState === XMLHttpRequest.DONE) {
if ((xhr.status >= 200 && xhr.status < 300) || xhr.status === 0 ) {
var blob = new Blob([xhr.response], {type: 'application/octet-stream'});
blob.name = name;
resolve(blob);
}else
{
}
else {
console.error("Error reading file " + url + " status:" + xhr.status + ", statusText:" + xhr.statusText);
reject({
status: this.status,
status: xhr.status,
statusText: xhr.statusText
});
}
}
};
xhr.onerror = function () {
console.error("Error reading file " + url + " status:" + xhr.status + ", statusText:" + xhr.statusText);
reject({
status: this.status,
status: xhr.status,
statusText: xhr.statusText
});
};