From af40739e9036c15983bdac5fb81135e5b33eb194 Mon Sep 17 00:00:00 2001 From: Gabriel Hernandez Date: Thu, 20 Mar 2025 22:47:35 +0000 Subject: [PATCH] add error for custom profile with wrong variable (#27375) For #26606 add error message when custom profile contains variable that is not supported --- .../components/ProfileUploader/helpers.tsx | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/frontend/pages/ManageControlsPage/OSSettings/cards/CustomSettings/components/ProfileUploader/helpers.tsx b/frontend/pages/ManageControlsPage/OSSettings/cards/CustomSettings/components/ProfileUploader/helpers.tsx index 4a3defbf1c..6c849605a7 100644 --- a/frontend/pages/ManageControlsPage/OSSettings/cards/CustomSettings/components/ProfileUploader/helpers.tsx +++ b/frontend/pages/ManageControlsPage/OSSettings/cards/CustomSettings/components/ProfileUploader/helpers.tsx @@ -26,7 +26,15 @@ export const parseFile = async (file: File): Promise<[string, string]> => { }; export const DEFAULT_ERROR_MESSAGE = - "Couldn’t add configuration profile. Please try again."; + "Couldn't add configuration profile. Please try again."; + +const generateUnsupportedVariableErrMsg = (errMsg: string) => { + const regex = /\$[A-Z0-9_]+/; + const varName = errMsg.match(regex); + return varName + ? `Couldn't add. Variable "${varName[0]}" doesn't exist.` + : DEFAULT_ERROR_MESSAGE; +}; /** We want to add some additional messageing to some of the error messages so * we add them in this function. Otherwise, we'll just return the error message from the @@ -64,5 +72,9 @@ export const getErrorMessage = (err: AxiosResponse) => { return generateSecretErrMsg(err); } + if (apiReason.includes("Fleet variable")) { + return generateUnsupportedVariableErrMsg(apiReason); + } + return apiReason || DEFAULT_ERROR_MESSAGE; };