Fixed a bug in the RequestUtil.js

This commit is contained in:
Mathias Wagner 2023-08-02 15:02:16 +02:00
parent b3016f9031
commit 3b915851f0
Signed by: Mathias
GPG Key ID: B8DC354B0A1F5B44

View File

@ -11,11 +11,12 @@ export const request = async (url, method, body, headers) => {
if (response.status === 401) throw new Error("Unauthorized"); if (response.status === 401) throw new Error("Unauthorized");
const data = await response.json(); const rawData = await response.text();
const data = rawData ? JSON.parse(rawData) : rawData.toString();
if (data.code >= 300) throw new Error(data.message); if (data.code >= 300) throw new Error(data.message);
if (!response.ok) throw new Error(await response.text()); if (!response.ok) throw new Error(data.message);
return data; return data;
} }