From 84caf3ba5baf6481b12112ae12a0f79a4f7a6e98 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sat, 8 Dec 2018 14:41:03 +0100 Subject: Switch from XMLHttpRequest to fetch API --- src/renderer/util.ts | 32 ++------------------------------ 1 file changed, 2 insertions(+), 30 deletions(-) (limited to 'src') diff --git a/src/renderer/util.ts b/src/renderer/util.ts index cea404b..4fedbd5 100644 --- a/src/renderer/util.ts +++ b/src/renderer/util.ts @@ -46,37 +46,9 @@ export class Listenable { } } -export function get(url: string): Promise { - return new Promise((resolve, reject) => { - const xhr = new XMLHttpRequest(); - - const handleError = () => { - if (xhr.readyState !== xhr.DONE) { - reject(new Error('HTTP request ended in state ' + xhr.readyState)); - return; - } - - reject(new Error('HTTP request returned status ' + xhr.status)); - }; - - xhr.addEventListener('error', handleError); - - xhr.addEventListener('load', () => { - if (xhr.readyState !== xhr.DONE || xhr.status !== 200) { - handleError(); - return; - } - - resolve(xhr); - }); - - xhr.open('GET', url, true); - xhr.send(); - }); -} - export async function getJSON(url: string): Promise { - return JSON.parse((await get(url)).responseText); + const res = await window.fetch(url); + return await res.json(); } export function nextAnimationFrame(): Promise { -- cgit v1.2.3