2024-12-24 21:26:24 +00:00
|
|
|
import { getErrorReason } from "interfaces/errors";
|
2025-01-02 18:06:23 +00:00
|
|
|
import { generateSecretErrMsg } from "pages/SoftwarePage/helpers";
|
2023-10-10 22:00:45 +00:00
|
|
|
|
2025-03-20 20:44:09 +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
|
2024-12-24 21:26:24 +00:00
|
|
|
export const getErrorMessage = (err: unknown) => {
|
|
|
|
|
const apiErrMessage = getErrorReason(err);
|
|
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
apiErrMessage.includes(
|
|
|
|
|
"File type not supported. Only .sh and .ps1 file type is allowed"
|
|
|
|
|
)
|
|
|
|
|
) {
|
2025-03-20 20:44:09 +00:00
|
|
|
return "Couldn't add. The file should be .sh or .ps1 file.";
|
2024-12-24 21:26:24 +00:00
|
|
|
} else if (apiErrMessage.includes("Secret variable")) {
|
2025-01-02 18:06:23 +00:00
|
|
|
return generateSecretErrMsg(err);
|
2024-12-24 21:26:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return apiErrMessage || DEFAULT_ERROR_MESSAGE;
|
2023-10-10 22:00:45 +00:00
|
|
|
};
|