Refactor httpGetter.
This commit is contained in:
parent
2116a55549
commit
8c08607a3a
@ -1,16 +1,14 @@
|
|||||||
function HttpGetter(): void {}
|
function HttpGetter(): void {}
|
||||||
|
|
||||||
HttpGetter.prototype.get = filename => new Promise((whohoo, doh) => {
|
HttpGetter.prototype.get = filename => new Promise((resolve, reject) => {
|
||||||
const xhr = new XMLHttpRequest();
|
fetch(filename).then(response => {
|
||||||
xhr.addEventListener('load', (e) => {
|
if (response.ok) {
|
||||||
if (xhr.status === 200) {
|
resolve(response.json());
|
||||||
whohoo(xhr.responseText);
|
} else {
|
||||||
return;
|
reject(`failed with status ${response.status} : ${response.statusText}`);
|
||||||
}
|
}
|
||||||
doh('failed with status ' + xhr.status + ': ' + xhr.statusText);
|
return;
|
||||||
});
|
});
|
||||||
xhr.open('GET', filename);
|
|
||||||
xhr.send();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
export {
|
export {
|
||||||
|
Loading…
Reference in New Issue
Block a user