diff --git a/packages/pl-fe/src/api/index.ts b/packages/pl-fe/src/api/index.ts index efd01cce9..9de440028 100644 --- a/packages/pl-fe/src/api/index.ts +++ b/packages/pl-fe/src/api/index.ts @@ -13,23 +13,24 @@ type PlfeResponse = 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)) => {