From fc9772c50b757f5ebb3639ef8d329941b3aa1f99 Mon Sep 17 00:00:00 2001 From: ledouxm Date: Wed, 9 Oct 2024 19:23:25 +0200 Subject: [PATCH] fix: little oopsie --- packages/frontend/src/api.ts | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/packages/frontend/src/api.ts b/packages/frontend/src/api.ts index 5787f6b..6cf9ea9 100644 --- a/packages/frontend/src/api.ts +++ b/packages/frontend/src/api.ts @@ -7,16 +7,23 @@ import { createStore, get, set } from "idb-keyval"; export const apiStore = createStore("auth", "access"); export const createApiClientWithUrl = (url: string) => { - return createApiClient((method, url, parameters) => { - const { body, query, header } = parameters || {}; - - return ofetch(url, { - method, - body: body as any, - query, - headers: { ...header, Authorization: ref.token ? `Bearer ${ref.token}` : undefined } as Record, - }); - }, url); + try { + const api = createApiClient((method, url, parameters) => { + const { body, query, header } = parameters || {}; + + return ofetch(url, { + method, + body: body as any, + query, + headers: { ...header, Authorization: ref.token ? `Bearer ${ref.token}` : undefined } as Record, + }); + }, url); + + return api; + } catch (e) { + console.error("error creating api client", e); + return null; + } }; export const api = createApiClientWithUrl(ENV.VITE_BACKEND_URL);