Merge pull request #679 from bluewave-labs/fix/safe-data-access
Add safe data access to monitorDetails
This commit is contained in:
2 files changed
+11
-4
No files matched your search
@@ -16,7 +16,6 @@ import {
|
|||||||
formatDurationRounded,
|
formatDurationRounded,
|
||||||
} from "../../../Utils/timeUtils";
|
} from "../../../Utils/timeUtils";
|
||||||
import "./index.css";
|
import "./index.css";
|
||||||
import MonitorDetails60MinChart from "../../../Components/Charts/MonitorDetails60MinChart";
|
|
||||||
import Breadcrumbs from "../../../Components/Breadcrumbs";
|
import Breadcrumbs from "../../../Components/Breadcrumbs";
|
||||||
import { logger } from "../../../Utils/Logger";
|
import { logger } from "../../../Utils/Logger";
|
||||||
|
|
||||||
@@ -131,7 +130,7 @@ const DetailsPage = () => {
|
|||||||
50,
|
50,
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
setMonitor(res.data.data);
|
setMonitor(res?.data?.data ?? {});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(error);
|
logger.error(error);
|
||||||
navigate("/not-found", { replace: true });
|
navigate("/not-found", { replace: true });
|
||||||
@@ -144,11 +143,16 @@ const DetailsPage = () => {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchCertificate = async () => {
|
const fetchCertificate = async () => {
|
||||||
|
try {
|
||||||
const res = await networkService.getCertificateExpiry(
|
const res = await networkService.getCertificateExpiry(
|
||||||
authToken,
|
authToken,
|
||||||
monitorId
|
monitorId
|
||||||
);
|
);
|
||||||
setCertificateExpiry(res.data.data.certificateDate);
|
setCertificateExpiry(res?.data?.data?.certificateDate ?? "N/A");
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
fetchCertificate();
|
fetchCertificate();
|
||||||
}, [authToken, monitorId]);
|
}, [authToken, monitorId]);
|
||||||
|
|||||||
@@ -172,6 +172,9 @@ const getMonitorStatsById = async (req) => {
|
|||||||
|
|
||||||
// Get monitor
|
// Get monitor
|
||||||
const monitor = await Monitor.findById(monitorId);
|
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
|
// Determine if this is a pagespeed monitor or an http/ping monitor
|
||||||
let model =
|
let model =
|
||||||
@@ -263,7 +266,7 @@ const getMonitorStatsById = async (req) => {
|
|||||||
|
|
||||||
return monitorStats;
|
return monitorStats;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
throw error;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user