util: add fetch error handling

This commit is contained in:
Matthias Schiffer 2018-12-08 14:43:23 +01:00
parent 84caf3ba5b
commit 33926af829
Signed by: neocturne
GPG key ID: 16EF3F64CB201D9C

View file

@ -48,6 +48,9 @@ export class Listenable<T extends any[]> {
export async function getJSON(url: string): Promise<any> { export async function getJSON(url: string): Promise<any> {
const res = await window.fetch(url); const res = await window.fetch(url);
if (res.status < 200 || res.status >= 300)
throw new Error(res.statusText);
return await res.json(); return await res.json();
} }