mirror of
https://github.com/fleetdm/fleet
synced 2026-05-23 17:08:53 +00:00
update the label error message (#24932)
relates to #24537 updates the delete label error when label is used for software - [x] Manual QA for all new/changed functionality
This commit is contained in:
parent
e6efcf7238
commit
863e680253
2 changed files with 26 additions and 8 deletions
|
|
@ -99,7 +99,7 @@ import {
|
|||
MANAGE_HOSTS_PAGE_FILTER_KEYS,
|
||||
MANAGE_HOSTS_PAGE_LABEL_INCOMPATIBLE_QUERY_PARAMS,
|
||||
} from "./HostsPageConfig";
|
||||
import { isAcceptableStatus } from "./helpers";
|
||||
import { getDeleteLabelErrorMessages, isAcceptableStatus } from "./helpers";
|
||||
|
||||
import DeleteSecretModal from "../../../components/EnrollSecrets/DeleteSecretModal";
|
||||
import SecretEditorModal from "../../../components/EnrollSecrets/SecretEditorModal";
|
||||
|
|
@ -1061,13 +1061,7 @@ const ManageHostsPage = ({
|
|||
);
|
||||
renderFlash("success", "Successfully deleted label.");
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
renderFlash(
|
||||
"error",
|
||||
getErrorReason(error).includes("built-in")
|
||||
? "Built-in labels can’t be modified or deleted."
|
||||
: "Could not delete label. Please try again."
|
||||
);
|
||||
renderFlash("error", getDeleteLabelErrorMessages(error));
|
||||
} finally {
|
||||
setIsUpdatingLabel(false);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
import { getErrorReason } from "interfaces/errors";
|
||||
|
||||
export const isAcceptableStatus = (filter: string): boolean => {
|
||||
return (
|
||||
filter === "new" ||
|
||||
|
|
@ -21,3 +23,25 @@ export const isValidPemCertificate = (cert: string): boolean => {
|
|||
|
||||
return regexPemHeader.test(cert) && regexPemFooter.test(cert);
|
||||
};
|
||||
|
||||
const hasStatusKey = (value: unknown): value is { status: number } => {
|
||||
return (
|
||||
typeof value === "object" &&
|
||||
value !== null &&
|
||||
"status" in value &&
|
||||
typeof (value as any).status === "number"
|
||||
);
|
||||
};
|
||||
|
||||
export const getDeleteLabelErrorMessages = (error: unknown): string => {
|
||||
// unprocessable content status. Label is used in a custom profile
|
||||
// or software target. we have to check that status exists on the error object
|
||||
// before we can access it.
|
||||
if (hasStatusKey(error) && error.status === 422) {
|
||||
return getErrorReason(error).includes("built-in")
|
||||
? "Built-in labels can't be modified or deleted."
|
||||
: "Couldn't delete. Software uses this label as a custom target. Please delete the software and try again.";
|
||||
}
|
||||
|
||||
return "Could not delete label. Please try again.";
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue