From 3a166b8ed4712df58e5bb6bd090a3a06983d9439 Mon Sep 17 00:00:00 2001 From: Mossroy Date: Mon, 19 Jun 2017 22:21:21 +0200 Subject: [PATCH] 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 --- tests/tests.js | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/tests/tests.js b/tests/tests.js index 91113098..2d150ac8 100644 --- a/tests/tests.js +++ b/tests/tests.js @@ -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 ) { - var blob = new Blob([xhr.response], {type: 'application/octet-stream'}); - blob.name = name; - resolve(blob); - }else - { - reject({ - status: this.status, - statusText: xhr.statusText - }); + 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 { + console.error("Error reading file " + url + " status:" + xhr.status + ", statusText:" + xhr.statusText); + reject({ + 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 }); };