diff --git a/src/api/api.js b/src/api/api.js index b5d3697..3f67f4a 100644 --- a/src/api/api.js +++ b/src/api/api.js @@ -5,20 +5,16 @@ function getHeaders() { return headers; } -function internalFetch(url, options) { - return fetch(url, options).then((res) => - res.text().then((text) => { - let t = text ? JSON.parse(text) : res.statusText; - if (!res.ok) { - if (res.status === 404) throw new Error(t || "Not found"); - - if (res.status >= 400 && res.status < 600 && t) throw t; - - throw new Error(t || "Unknown error"); - } - return t; - }) - ); +async function internalFetch(url, options) { + const res = await fetch(url, options); + const text = await res.text(); + const t = text ? JSON.parse(text) : res.statusText; + if (!res.ok) { + if (res.status === 404) throw new Error(t || "Not found"); + if (res.status >= 400 && res.status < 600 && t) throw t; + throw new Error(t || "Unknown error"); + } + return t; } export function post(url, body) {