From d8e2faaade07152263cd29860c401f718ec02d6d Mon Sep 17 00:00:00 2001 From: Sulejman Karisik Date: Fri, 24 May 2024 14:33:31 +0200 Subject: [PATCH] fix: fetch application request fails silently and makes renedering issues --- src/app/applications/[id]/page.tsx | 18 +++++++++++++++++- .../application/ApplicationProvider.tsx | 7 ++++--- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/app/applications/[id]/page.tsx b/src/app/applications/[id]/page.tsx index 8e8ced52..e3025a20 100644 --- a/src/app/applications/[id]/page.tsx +++ b/src/app/applications/[id]/page.tsx @@ -44,7 +44,23 @@ export default function ApplicationDetailsPage() { } }, [error]); - if (!application) return; + if (!application) { + return ( + + {alert && ( + { + onCloseAlert(); + clearError(); + }} + className="mb-8" + /> + )} + + ); + } const events = application.events; const lastEvent = events[0]; diff --git a/src/providers/application/ApplicationProvider.tsx b/src/providers/application/ApplicationProvider.tsx index b9de89d2..eb81c9d9 100644 --- a/src/providers/application/ApplicationProvider.tsx +++ b/src/providers/application/ApplicationProvider.tsx @@ -130,14 +130,15 @@ function ApplicationProvider({ children }: ApplicationProviderProps) { const fetchApplication = useCallback(async () => { dispatch({ type: ApplicationActionType.LOADING }); - try { - const response = await fetch(`/api/applications/${id}`); + const response = await fetch(`/api/applications/${id}`); + + if (response.ok) { const retrievedApplication = await response.json(); dispatch({ type: ApplicationActionType.APPLICATION_LOADED, payload: retrievedApplication, }); - } catch { + } else { dispatch({ type: ApplicationActionType.REJECTED, payload: "Failed to fetch application",