pl-fe: use async function

Signed-off-by: mkljczk <git@mkljczk.pl>
This commit is contained in:
mkljczk
2024-12-22 19:45:22 +01:00
parent ab7f25ccf7
commit 46565d823e

View File

@ -13,23 +13,24 @@ type PlfeResponse<T = any> = Response & { data: string; json: T };
* It uses FE_SUBDIRECTORY and parses JSON if possible.
* No authorization is needed.
*/
const staticFetch = (input: URL | RequestInfo, init?: RequestInit | undefined) => {
const staticFetch = async (input: URL | RequestInfo, init?: RequestInit | undefined) => {
const fullPath = buildFullPath(input.toString(), BuildConfig.BACKEND_URL);
return fetch(fullPath, init).then(async (response) => {
if (!response.ok) throw { response };
const data = await response.text();
let json: any = undefined!;
try {
json = JSON.parse(data);
} catch (e) {
//
}
const response = await fetch(fullPath, init);
if (!response.ok) throw { response };
const { headers, ok, redirected, status, statusText, type, url } = response;
const data = await response.text();
return { headers, ok, redirected, status, statusText, type, url, data, json } as any as PlfeResponse;
});
let json: any = undefined!;
try {
json = JSON.parse(data);
} catch (e) {
//
}
const { headers, ok, redirected, status, statusText, type, url } = response;
return { headers, ok, redirected, status, statusText, type, url, data, json } as any as PlfeResponse;
};
const getClient = (state: RootState | (() => RootState)) => {