handle errors with XHR
This commit is contained in:
parent
213708d8dc
commit
42f3a62cac
@ -90,11 +90,21 @@ define([], function () {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Util.fetch = function (src, cb) {
|
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();
|
var xhr = new XMLHttpRequest();
|
||||||
xhr.open("GET", src, true);
|
xhr.open("GET", src, true);
|
||||||
xhr.responseType = "arraybuffer";
|
xhr.responseType = "arraybuffer";
|
||||||
xhr.onload = function () {
|
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);
|
xhr.send(null);
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user