Refacto error handling in trust center front end
Signed-off-by: Sacha Al Himdani <sacha@getprobo.com>
This commit is contained in:
@@ -23,7 +23,7 @@ export function PublicTrustCenterLayout({ organizationName, organizationLogo, ch
|
|||||||
credentials: 'include',
|
credentials: 'include',
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Logout failed:', error);
|
console.error('Logout failed');
|
||||||
} finally {
|
} finally {
|
||||||
window.location.href = "/";
|
window.location.href = "/";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -95,7 +95,17 @@ export default function TrustCenterAccessPage() {
|
|||||||
credentials: 'include',
|
credentials: 'include',
|
||||||
body: JSON.stringify({ token }),
|
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 => {
|
.then(data => {
|
||||||
if (data.success) {
|
if (data.success) {
|
||||||
navigate(`/trust/${slug}`);
|
navigate(`/trust/${slug}`);
|
||||||
@@ -104,8 +114,8 @@ export default function TrustCenterAccessPage() {
|
|||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch((error) => {
|
||||||
setError(__("Authentication failed"));
|
setError(error.message || __("Authentication failed"));
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
});
|
});
|
||||||
}, [slug, token, __, navigate]);
|
}, [slug, token, __, navigate]);
|
||||||
|
|||||||
Reference in New Issue
Block a user