diff --git a/frontend/pages/hosts/details/HostDetailsPage/modals/CancelActivityModal/helpers.ts b/frontend/pages/hosts/details/HostDetailsPage/modals/CancelActivityModal/helpers.ts index ba6c51f65a..d38446e394 100644 --- a/frontend/pages/hosts/details/HostDetailsPage/modals/CancelActivityModal/helpers.ts +++ b/frontend/pages/hosts/details/HostDetailsPage/modals/CancelActivityModal/helpers.ts @@ -1,10 +1,19 @@ -import { getErrorReason } from "interfaces/errors"; +import { isAxiosError } from "axios"; -const DEFAULT_ERROR_MESSAGE = "An error occurred. Please try again."; +const DEFAULT_ERR_MESSAGE = "Couldn't cancel activity. Please try again."; +const LOCK_WIPE_ERR_MESSAGE = + "Couldn't cancel activity. Lock and wipe can't be canceled if they're about to run to prevent you from losing access to the host."; +const ACTIVITY_ALREADY_HAPPENED_ERR_MESSAGE = + "Couldn't cancel activity. Activity already happened."; // eslint-disable-next-line import/prefer-default-export export const getErrorMessage = (err: unknown) => { - const reason = getErrorReason(err); + if (isAxiosError(err)) { + if (err.status === 404) return ACTIVITY_ALREADY_HAPPENED_ERR_MESSAGE; - return `Couldn't cancel activity. ${reason || DEFAULT_ERROR_MESSAGE}`; + // display server error message if error is 400 + if (err.status === 400) return LOCK_WIPE_ERR_MESSAGE; + } + + return DEFAULT_ERR_MESSAGE; };