diff --git a/Client/src/Pages/Monitors/Details/index.jsx b/Client/src/Pages/Monitors/Details/index.jsx index 79fba3b6b..f7b13a0e8 100644 --- a/Client/src/Pages/Monitors/Details/index.jsx +++ b/Client/src/Pages/Monitors/Details/index.jsx @@ -16,7 +16,6 @@ import { formatDurationRounded, } from "../../../Utils/timeUtils"; import "./index.css"; -import MonitorDetails60MinChart from "../../../Components/Charts/MonitorDetails60MinChart"; import Breadcrumbs from "../../../Components/Breadcrumbs"; const StatBox = ({ title, value }) => { @@ -129,9 +128,10 @@ const DetailsPage = () => { }, } ); - setMonitor(res.data.data); + setMonitor(res?.data?.data ?? {}); } catch (error) { - console.error("Error fetching monitor of id: " + monitorId); + console.error(error); + navigate("/not-found"); } }, [authToken, monitorId, navigate, dateRange]); @@ -142,15 +142,19 @@ const DetailsPage = () => { useEffect(() => { const fetchCertificate = async () => { - const res = await axiosInstance.get( - `/monitors/certificate/${monitorId}`, - { - headers: { - Authorization: `Bearer ${authToken}`, - }, - } - ); - setCertificateExpiry(res.data.data.certificateDate); + try { + const res = await axiosInstance.get( + `/monitors/certificate/${monitorId}`, + { + headers: { + Authorization: `Bearer ${authToken}`, + }, + } + ); + setCertificateExpiry(res?.data?.data?.certificateDate ?? "N/A"); + } catch (error) { + console.error(error); + } }; fetchCertificate(); }, [authToken, monitorId]); diff --git a/Client/src/Pages/NotFound/index.jsx b/Client/src/Pages/NotFound/index.jsx index 68120b0a3..ef4b37839 100644 --- a/Client/src/Pages/NotFound/index.jsx +++ b/Client/src/Pages/NotFound/index.jsx @@ -33,7 +33,6 @@ const DefaultValue = { */ const NotFound = ({ title = DefaultValue.title, desc = DefaultValue.desc }) => { const navigate = useNavigate(); - console.log("NOT FOUND"); return ( diff --git a/Server/db/mongo/modules/monitorModule.js b/Server/db/mongo/modules/monitorModule.js index 0fc56c755..05cef7646 100644 --- a/Server/db/mongo/modules/monitorModule.js +++ b/Server/db/mongo/modules/monitorModule.js @@ -172,6 +172,9 @@ const getMonitorStatsById = async (req) => { // Get monitor const monitor = await Monitor.findById(monitorId); + if (monitor === null || monitor === undefined) { + throw new Error(errorMessages.DB_FIND_MONTIOR_BY_ID(monitorId)); + } // Determine if this is a pagespeed monitor or an http/ping monitor let model = @@ -263,7 +266,7 @@ const getMonitorStatsById = async (req) => { return monitorStats; } catch (error) { - console.log(error); + throw error; } };