add error message for cancel activities (#27937)

For #27410

add error messages for cancel activities.
This commit is contained in:
Gabriel Hernandez 2025-04-08 15:03:09 +01:00 committed by GitHub
parent 4e653472f1
commit a80d806087
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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;
};