From c71237daa29b2654f75871a74d5ae33542c7913c Mon Sep 17 00:00:00 2001 From: Gabriel Hernandez Date: Wed, 23 Oct 2024 18:15:53 +0100 Subject: [PATCH] add error message for host having mdm off to host details (#23080) relates to #22041 This adds an error message when refetching a host when mdm is not turned on for it. This was accidentally added to the My Device page, so we are moving it to the Host details page. --- .../hosts/details/DeviceUserPage/helpers.ts | 12 +----------- .../details/HostDetailsPage/HostDetailsPage.tsx | 4 ++-- .../hosts/details/HostDetailsPage/helpers.ts | 16 ++++++++++++++++ 3 files changed, 19 insertions(+), 13 deletions(-) create mode 100644 frontend/pages/hosts/details/HostDetailsPage/helpers.ts diff --git a/frontend/pages/hosts/details/DeviceUserPage/helpers.ts b/frontend/pages/hosts/details/DeviceUserPage/helpers.ts index a5a362e026..80c5037131 100644 --- a/frontend/pages/hosts/details/DeviceUserPage/helpers.ts +++ b/frontend/pages/hosts/details/DeviceUserPage/helpers.ts @@ -1,16 +1,6 @@ -import { getErrorReason } from "interfaces/errors"; - const DEFAULT_ERROR_MESSAGE = "refetch error."; // eslint-disable-next-line import/prefer-default-export export const getErrorMessage = (e: unknown, hostName: string) => { - let errorMessage = getErrorReason(e, { - reasonIncludes: "Host does not have MDM turned on", - }); - - if (!errorMessage) { - errorMessage = DEFAULT_ERROR_MESSAGE; - } - - return `Host "${hostName}" ${errorMessage}`; + return `Host "${hostName}" ${DEFAULT_ERROR_MESSAGE}`; }; diff --git a/frontend/pages/hosts/details/HostDetailsPage/HostDetailsPage.tsx b/frontend/pages/hosts/details/HostDetailsPage/HostDetailsPage.tsx index 0c56d7c6ca..1ce179ae87 100644 --- a/frontend/pages/hosts/details/HostDetailsPage/HostDetailsPage.tsx +++ b/frontend/pages/hosts/details/HostDetailsPage/HostDetailsPage.tsx @@ -104,6 +104,7 @@ import { import WipeModal from "./modals/WipeModal"; import SoftwareDetailsModal from "../cards/Software/SoftwareDetailsModal"; import { parseHostSoftwareQueryParams } from "../cards/Software/HostSoftware"; +import { getErrorMessage } from "./helpers"; const baseClass = "host-details"; @@ -579,8 +580,7 @@ const HostDetailsPage = ({ }, 1000); }); } catch (error) { - console.log(error); - renderFlash("error", `Host "${host.display_name}" refetch error`); + renderFlash("error", getErrorMessage(error, host.display_name)); setShowRefetchSpinner(false); } } diff --git a/frontend/pages/hosts/details/HostDetailsPage/helpers.ts b/frontend/pages/hosts/details/HostDetailsPage/helpers.ts new file mode 100644 index 0000000000..a5a362e026 --- /dev/null +++ b/frontend/pages/hosts/details/HostDetailsPage/helpers.ts @@ -0,0 +1,16 @@ +import { getErrorReason } from "interfaces/errors"; + +const DEFAULT_ERROR_MESSAGE = "refetch error."; + +// eslint-disable-next-line import/prefer-default-export +export const getErrorMessage = (e: unknown, hostName: string) => { + let errorMessage = getErrorReason(e, { + reasonIncludes: "Host does not have MDM turned on", + }); + + if (!errorMessage) { + errorMessage = DEFAULT_ERROR_MESSAGE; + } + + return `Host "${hostName}" ${errorMessage}`; +};