add error for custom profile with wrong variable (#27375)

For #26606

add error message when custom profile contains variable that is not
supported
This commit is contained in:
Gabriel Hernandez 2025-03-20 22:47:35 +00:00 committed by GitHub
parent c30d3ac03b
commit af40739e90
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -26,7 +26,15 @@ export const parseFile = async (file: File): Promise<[string, string]> => {
};
export const DEFAULT_ERROR_MESSAGE =
"Couldnt 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<IApiError>) => {
return generateSecretErrMsg(err);
}
if (apiReason.includes("Fleet variable")) {
return generateUnsupportedVariableErrMsg(apiReason);
}
return apiReason || DEFAULT_ERROR_MESSAGE;
};