fleet/frontend/pages/ManageControlsPage/Scripts/components/ScriptUploader/helpers.ts

22 lines
677 B
TypeScript
Raw Normal View History

import { getErrorReason } from "interfaces/errors";
import { generateSecretErrMsg } from "pages/SoftwarePage/helpers";
2023-10-10 22:00:45 +00:00
const DEFAULT_ERROR_MESSAGE = "Couldn't add. Please try again.";
2023-10-10 22:00:45 +00:00
// eslint-disable-next-line import/prefer-default-export
export const getErrorMessage = (err: unknown) => {
const apiErrMessage = getErrorReason(err);
if (
apiErrMessage.includes(
"File type not supported. Only .sh and .ps1 file type is allowed"
)
) {
return "Couldn't add. The file should be .sh or .ps1 file.";
} else if (apiErrMessage.includes("Secret variable")) {
return generateSecretErrMsg(err);
}
return apiErrMessage || DEFAULT_ERROR_MESSAGE;
2023-10-10 22:00:45 +00:00
};