mirror of
https://github.com/khairul169/garage-webui.git
synced 2026-09-15 00:43:21 +07:00
feat: properly handle data fetching state on view bucket page
This commit is contained in:
+9
-11
@@ -30,23 +30,21 @@ const api = {
|
||||
headers: { ...headers, ...(options?.headers || {}) },
|
||||
});
|
||||
|
||||
if (!res.ok) {
|
||||
const json = await res.json().catch(() => {});
|
||||
const message = json?.message || res.statusText;
|
||||
throw new Error(message);
|
||||
}
|
||||
|
||||
const isJson = res.headers
|
||||
.get("Content-Type")
|
||||
?.includes("application/json");
|
||||
const data = isJson ? await res.json() : await res.text();
|
||||
|
||||
if (isJson) {
|
||||
const json = (await res.json()) as T;
|
||||
return json;
|
||||
if (!res.ok) {
|
||||
const message = isJson
|
||||
? data?.message
|
||||
: typeof data === "string"
|
||||
? data
|
||||
: res.statusText;
|
||||
throw new Error(message);
|
||||
}
|
||||
|
||||
const text = await res.text();
|
||||
return text as unknown as T;
|
||||
return data as unknown as T;
|
||||
},
|
||||
|
||||
async get<T = any>(url: string, options?: Partial<FetchOptions>) {
|
||||
|
||||
Reference in New Issue
Block a user