From bbac3903826e01c9b347bdb2b9add28f3467d803 Mon Sep 17 00:00:00 2001 From: Sacha Al Himdani Date: Tue, 5 Aug 2025 11:05:04 +0200 Subject: [PATCH] Refacto error handling in trust center front end Signed-off-by: Sacha Al Himdani --- .../src/layouts/PublicTrustCenterLayout.tsx | 2 +- apps/console/src/pages/TrustCenterAccessPage.tsx | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/apps/console/src/layouts/PublicTrustCenterLayout.tsx b/apps/console/src/layouts/PublicTrustCenterLayout.tsx index 42dd753ff..e5caed9aa 100644 --- a/apps/console/src/layouts/PublicTrustCenterLayout.tsx +++ b/apps/console/src/layouts/PublicTrustCenterLayout.tsx @@ -23,7 +23,7 @@ export function PublicTrustCenterLayout({ organizationName, organizationLogo, ch credentials: 'include', }); } catch (error) { - console.error('Logout failed:', error); + console.error('Logout failed'); } finally { window.location.href = "/"; } diff --git a/apps/console/src/pages/TrustCenterAccessPage.tsx b/apps/console/src/pages/TrustCenterAccessPage.tsx index 75d2aa8ad..81bd5c61a 100644 --- a/apps/console/src/pages/TrustCenterAccessPage.tsx +++ b/apps/console/src/pages/TrustCenterAccessPage.tsx @@ -95,7 +95,17 @@ export default function TrustCenterAccessPage() { credentials: 'include', body: JSON.stringify({ token }), }) - .then(response => response.json()) + .then(async response => { + if (!response.ok) { + try { + const errorData = await response.json(); + throw new Error(errorData.message || `HTTP ${response.status}: ${response.statusText}`); + } catch { + throw new Error(`HTTP ${response.status}: ${response.statusText}`); + } + } + return response.json(); + }) .then(data => { if (data.success) { navigate(`/trust/${slug}`); @@ -104,8 +114,8 @@ export default function TrustCenterAccessPage() { setLoading(false); } }) - .catch(() => { - setError(__("Authentication failed")); + .catch((error) => { + setError(error.message || __("Authentication failed")); setLoading(false); }); }, [slug, token, __, navigate]);