From d9aeb6b79c30a9316f05771abfed4f89411e9c6a Mon Sep 17 00:00:00 2001 From: anovazzi1 Date: Mon, 20 Nov 2023 19:29:39 -0300 Subject: [PATCH] fix(storeContext.tsx): fix setLoadingApiKey not being called in catch block to stop loading state fix(API/index.ts): fix BASE_URL_API missing slash causing incorrect API endpoint URL fix(StorePage/index.tsx): add catch block to handle error when fetching store tags and log error message --- src/frontend/src/contexts/storeContext.tsx | 1 + src/frontend/src/controllers/API/index.ts | 2 +- src/frontend/src/pages/StorePage/index.tsx | 15 ++++++++++----- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/frontend/src/contexts/storeContext.tsx b/src/frontend/src/contexts/storeContext.tsx index d1078de04..d9a3194c9 100644 --- a/src/frontend/src/contexts/storeContext.tsx +++ b/src/frontend/src/contexts/storeContext.tsx @@ -47,6 +47,7 @@ export function StoreProvider({ children }) { setValidApiKey(res?.is_valid ?? false); setLoadingApiKey(false); } catch (e) { + setLoadingApiKey(false); console.log(e); } }; diff --git a/src/frontend/src/controllers/API/index.ts b/src/frontend/src/controllers/API/index.ts index de177451e..3257c57af 100644 --- a/src/frontend/src/controllers/API/index.ts +++ b/src/frontend/src/controllers/API/index.ts @@ -732,7 +732,7 @@ export async function searchComponent( export async function checkHasApiKey() { try { - const res = await api.get(`${BASE_URL_API}/store/check/api_key`); + const res = await api.get(`${BASE_URL_API}store/check/api_key`); if (res?.status === 200) { return res.data; } diff --git a/src/frontend/src/pages/StorePage/index.tsx b/src/frontend/src/pages/StorePage/index.tsx index 086bef094..56dfda709 100644 --- a/src/frontend/src/pages/StorePage/index.tsx +++ b/src/frontend/src/pages/StorePage/index.tsx @@ -57,7 +57,7 @@ export default function StorePage(): JSX.Element { "You don't have an API Key. Please add one to use the Langflow Store.", ], }); - setLoading(false) + setLoading(false); } else if (!validApiKey) { setErrorData({ title: "API Key Error", @@ -87,10 +87,15 @@ export default function StorePage(): JSX.Element { function handleGetTags() { setLoadingTags(true); - getStoreTags().then((res) => { - setTags(res); - setLoadingTags(false); - }); + getStoreTags() + .then((res) => { + setTags(res); + setLoadingTags(false); + }) + .catch((err) => { + console.log(err); + setLoadingTags(false); + }); } function handleGetComponents() {