From a80d806087e54c9c97f62b5c6d28f3b6c1f44947 Mon Sep 17 00:00:00 2001 From: Gabriel Hernandez Date: Tue, 8 Apr 2025 15:03:09 +0100 Subject: [PATCH] add error message for cancel activities (#27937) For #27410 add error messages for cancel activities. --- .../modals/CancelActivityModal/helpers.ts | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) 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; };