mirror of
https://github.com/fleetdm/fleet
synced 2026-05-24 09:28:54 +00:00
add error message for cancel activities (#27937)
For #27410 add error messages for cancel activities.
This commit is contained in:
parent
4e653472f1
commit
a80d806087
1 changed files with 13 additions and 4 deletions
|
|
@ -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;
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue