util: add fetch error handling
This commit is contained in:
parent
84caf3ba5b
commit
33926af829
1 changed files with 3 additions and 0 deletions
|
@ -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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Reference in a new issue