From 0324df60c242a8093cb9a00d83a8cb80e3d24ac1 Mon Sep 17 00:00:00 2001 From: vik378 Date: Thu, 21 Mar 2024 14:45:50 +0100 Subject: [PATCH] added handling for server isnt around case --- frontend/src/components/TemplateDetails.jsx | 13 +++++++++++-- frontend/src/components/WiredTemplatesList.jsx | 15 ++++++++++++++- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/frontend/src/components/TemplateDetails.jsx b/frontend/src/components/TemplateDetails.jsx index 9e097d1..eb37f54 100644 --- a/frontend/src/components/TemplateDetails.jsx +++ b/frontend/src/components/TemplateDetails.jsx @@ -5,6 +5,7 @@ import { Card } from './Card'; export const TemplateDetails = ({endpoint}) => { let { templateName, objectID } = useParams(); + const [error, setError] = useState(null); const [details, setDetails] = useState([]); const navigate = useNavigate(); const [filterText, setFilterText] = useState(''); @@ -21,12 +22,20 @@ export const TemplateDetails = ({endpoint}) => { const data = await response.json(); setDetails(data); } - catch (error) {} + catch (error) { + setError(error.message); + } finally {} }; fetchDetails(); }, [endpoint, templateName, objectID]); - + if (error) { + return ( +
+ {error} +
+ ) + } return (
diff --git a/frontend/src/components/WiredTemplatesList.jsx b/frontend/src/components/WiredTemplatesList.jsx index b629406..027953d 100644 --- a/frontend/src/components/WiredTemplatesList.jsx +++ b/frontend/src/components/WiredTemplatesList.jsx @@ -5,6 +5,7 @@ import { ViewsList } from './ViewsList'; export const WiredTemplatesList = ({endpoint}) => { const [templates, setTemplates] = useState([]) + const [error, setError] = useState(null); const navigate = useNavigate(); useEffect(() => { @@ -19,10 +20,22 @@ export const WiredTemplatesList = ({endpoint}) => { const data = await response.json(); setTemplates(data); } - catch (error) {} + catch (error) { + setError(error.message) + } finally {} }; fetchTemplates(); }, [endpoint]); + if (error) { + return ( +
+ {error === 'Failed to fetch' ? + "Can't connect to the server. Maybe your session was inactive for too long? if that's the case, request a new session / restart the app." + : + error + } +
); + } return navigate(`/views/${idx}`, {state: {idx: idx}})} />;} \ No newline at end of file