mirror of
https://github.com/fleetdm/fleet
synced 2026-05-24 01:18:42 +00:00
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:
parent
c30d3ac03b
commit
af40739e90
1 changed files with 13 additions and 1 deletions
|
|
@ -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<IApiError>) => {
|
|||
return generateSecretErrMsg(err);
|
||||
}
|
||||
|
||||
if (apiReason.includes("Fleet variable")) {
|
||||
return generateUnsupportedVariableErrMsg(apiReason);
|
||||
}
|
||||
|
||||
return apiReason || DEFAULT_ERROR_MESSAGE;
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue