From e0a45cf338ea244975a4df8f74e93f4358d696c9 Mon Sep 17 00:00:00 2001 From: Mathias Wagner Date: Sun, 30 Jul 2023 20:01:44 +0200 Subject: [PATCH] Fixed a bug in the RequestUtil.js --- src/common/utils/RequestUtil.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/common/utils/RequestUtil.js b/src/common/utils/RequestUtil.js index a83cab0..9386816 100644 --- a/src/common/utils/RequestUtil.js +++ b/src/common/utils/RequestUtil.js @@ -9,9 +9,13 @@ export const request = async (url, method, body, headers) => { if (response.status === 401) throw new Error("Unauthorized"); + const data = await response.json(); + + if (data.code >= 300) throw new Error(data.message); + if (!response.ok) throw new Error(await response.text()); - return await response.json(); + return data; } export const sessionRequest = (url, method, token, body) => {