handle errors with XHR

pull/1/head
ansuz 2017-05-12 16:13:09 +02:00
parent 213708d8dc
commit 42f3a62cac
1 changed files with 11 additions and 1 deletions

View File

@ -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);
};