Refactor httpGetter.

This commit is contained in:
Spencer Ofwiti 2021-04-17 14:02:29 +03:00
parent 2116a55549
commit 8c08607a3a
1 changed files with 7 additions and 9 deletions

View File

@ -1,16 +1,14 @@
function HttpGetter(): void {}
HttpGetter.prototype.get = filename => new Promise((whohoo, doh) => {
const xhr = new XMLHttpRequest();
xhr.addEventListener('load', (e) => {
if (xhr.status === 200) {
whohoo(xhr.responseText);
return;
HttpGetter.prototype.get = filename => new Promise((resolve, reject) => {
fetch(filename).then(response => {
if (response.ok) {
resolve(response.json());
} else {
reject(`failed with status ${response.status} : ${response.statusText}`);
}
doh('failed with status ' + xhr.status + ': ' + xhr.statusText);
return;
});
xhr.open('GET', filename);
xhr.send();
});
export {