From 42f3a62cac345b4ffb5a6640d03ce35fd767c202 Mon Sep 17 00:00:00 2001 From: ansuz Date: Fri, 12 May 2017 16:13:09 +0200 Subject: [PATCH] handle errors with XHR --- www/common/common-util.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/www/common/common-util.js b/www/common/common-util.js index e62ed7016..bbd648f7c 100644 --- a/www/common/common-util.js +++ b/www/common/common-util.js @@ -90,11 +90,21 @@ define([], function () { }; Util.fetch = function (src, cb) { + var done = false; + var CB = function (err, res) { + if (done) { return; } + done = true; + cb(err, res); + }; + var xhr = new XMLHttpRequest(); xhr.open("GET", src, true); xhr.responseType = "arraybuffer"; xhr.onload = function () { - return void cb(void 0, new Uint8Array(xhr.response)); + return void CB(void 0, new Uint8Array(xhr.response)); + }; + xhr.onerror = function () { + CB('XHR_ERROR'); }; xhr.send(null); };