Update secret error messages across the UI (#25085)
relates to #24550 more updates to the various secret error messages after some API changes - [x] Manual QA for all new/changed functionality
This commit is contained in:
+2
-1
@@ -1,6 +1,7 @@
|
||||
import React from "react";
|
||||
import { AxiosResponse } from "axios";
|
||||
import { IApiError } from "interfaces/errors";
|
||||
import { generateSecretErrMsg } from "pages/SoftwarePage/helpers";
|
||||
|
||||
export const parseFile = async (file: File): Promise<[string, string]> => {
|
||||
// get the file name and extension
|
||||
@@ -60,7 +61,7 @@ export const getErrorMessage = (err: AxiosResponse<IApiError>) => {
|
||||
}
|
||||
|
||||
if (apiReason.includes("Secret variable")) {
|
||||
return apiReason.replace("missing from database", "doesn't exist");
|
||||
return generateSecretErrMsg(err);
|
||||
}
|
||||
|
||||
return apiReason || DEFAULT_ERROR_MESSAGE;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { getErrorReason } from "interfaces/errors";
|
||||
import { generateSecretErrMsg } from "pages/SoftwarePage/helpers";
|
||||
|
||||
const DEFAULT_ERROR_MESSAGE = "Couldn't upload. Please try again.";
|
||||
|
||||
@@ -13,7 +14,7 @@ export const getErrorMessage = (err: unknown) => {
|
||||
) {
|
||||
return "Couldn't upload. The file should be .sh or .ps1 file.";
|
||||
} else if (apiErrMessage.includes("Secret variable")) {
|
||||
return apiErrMessage.replace("missing from database", "doesn't exist");
|
||||
return generateSecretErrMsg(err);
|
||||
}
|
||||
|
||||
return apiErrMessage || DEFAULT_ERROR_MESSAGE;
|
||||
|
||||
@@ -6,6 +6,8 @@ import { LEARN_MORE_ABOUT_BASE_LINK } from "utilities/constants";
|
||||
|
||||
import CustomLink from "components/CustomLink";
|
||||
|
||||
import { generateSecretErrMsg } from "pages/SoftwarePage/helpers";
|
||||
|
||||
const DEFAULT_ERROR_MESSAGE = "Couldn't add. Please try again.";
|
||||
|
||||
// eslint-disable-next-line import/prefer-default-export
|
||||
@@ -30,7 +32,7 @@ export const getErrorMessage = (err: unknown) => {
|
||||
</>
|
||||
);
|
||||
} else if (reason.includes("Secret variable")) {
|
||||
return reason.replace("missing from database", "doesn't exist");
|
||||
return generateSecretErrMsg(err);
|
||||
} else if (reason.includes("Unable to extract necessary metadata")) {
|
||||
return (
|
||||
<>
|
||||
|
||||
+2
-2
@@ -12,7 +12,6 @@ import labelsAPI, { getCustomLabels } from "services/entities/labels";
|
||||
import { QueryContext } from "context/query";
|
||||
import { AppContext } from "context/app";
|
||||
import { NotificationContext } from "context/notification";
|
||||
import { getErrorReason } from "interfaces/errors";
|
||||
import { Platform, PLATFORM_DISPLAY_NAMES } from "interfaces/platform";
|
||||
import { ILabelSummary } from "interfaces/label";
|
||||
import useToggleSidePanel from "hooks/useToggleSidePanel";
|
||||
@@ -33,6 +32,7 @@ import { IFleetMaintainedAppFormData } from "./FleetAppDetailsForm/FleetAppDetai
|
||||
import AddFleetAppSoftwareModal from "./AddFleetAppSoftwareModal";
|
||||
|
||||
import {
|
||||
getErrorMessage,
|
||||
getFleetAppPolicyDescription,
|
||||
getFleetAppPolicyName,
|
||||
getFleetAppPolicyQuery,
|
||||
@@ -192,7 +192,7 @@ const FleetMaintainedAppDetailsPage = ({
|
||||
} catch (error) {
|
||||
// quick exit if there was an error adding the software. Skip the policy
|
||||
// creation.
|
||||
renderFlash("error", getErrorReason(error));
|
||||
renderFlash("error", getErrorMessage(error));
|
||||
setShowAddFleetAppSoftwareModal(false);
|
||||
return;
|
||||
}
|
||||
|
||||
+14
@@ -1,3 +1,7 @@
|
||||
import { getErrorReason } from "interfaces/errors";
|
||||
|
||||
import { generateSecretErrMsg } from "pages/SoftwarePage/helpers";
|
||||
|
||||
import fleetAppData from "../../../../../../server/mdm/maintainedapps/apps.json";
|
||||
|
||||
const NameToIdentifierMap: Record<string, string> = {
|
||||
@@ -40,3 +44,13 @@ export const getFleetAppPolicyDescription = (appName: string) => {
|
||||
export const getFleetAppPolicyQuery = (name: string) => {
|
||||
return getFleetAppData(name)?.automatic_policy_query;
|
||||
};
|
||||
|
||||
export const getErrorMessage = (err: unknown) => {
|
||||
const reason = getErrorReason(err);
|
||||
|
||||
if (reason.includes("Secret variable")) {
|
||||
return generateSecretErrMsg(err);
|
||||
}
|
||||
|
||||
return reason;
|
||||
};
|
||||
|
||||
@@ -6,6 +6,7 @@ import { ISoftwarePackage } from "interfaces/software";
|
||||
|
||||
import CustomLink from "components/CustomLink";
|
||||
import { LEARN_MORE_ABOUT_BASE_LINK } from "utilities/constants";
|
||||
import { generateSecretErrMsg } from "pages/SoftwarePage/helpers";
|
||||
|
||||
const DEFAULT_ERROR_MESSAGE = "Couldn't edit software. Please try again.";
|
||||
|
||||
@@ -36,9 +37,7 @@ export const getErrorMessage = (err: unknown, software: ISoftwarePackage) => {
|
||||
</>
|
||||
);
|
||||
} else if (reason.includes("Secret variable")) {
|
||||
return reason
|
||||
.replace("missing from database", "doesn't exist")
|
||||
.replace("Couldn't add", "Couldn't edit");
|
||||
return generateSecretErrMsg(err).replace("Couldn't add", "Couldn't edit");
|
||||
}
|
||||
|
||||
return reason || DEFAULT_ERROR_MESSAGE;
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
import { getErrorReason } from "interfaces/errors";
|
||||
|
||||
/**
|
||||
* helper function to generate error message for secret variables based
|
||||
* on the error reason.
|
||||
*/
|
||||
// eslint-disable-next-line import/prefer-default-export
|
||||
export const generateSecretErrMsg = (err: unknown) => {
|
||||
const reason = getErrorReason(err);
|
||||
|
||||
let errorType = "";
|
||||
if (getErrorReason(err, { nameEquals: "install script" })) {
|
||||
errorType = "install script";
|
||||
} else if (getErrorReason(err, { nameEquals: "post-install script" })) {
|
||||
errorType = "post-install script";
|
||||
} else if (getErrorReason(err, { nameEquals: "uninstall script" })) {
|
||||
errorType = "uninstall script";
|
||||
} else if (getErrorReason(err, { nameEquals: "profile" })) {
|
||||
errorType = "profile";
|
||||
}
|
||||
|
||||
if (errorType === "profile") {
|
||||
return reason
|
||||
.split(":")[1]
|
||||
.replace(/Secret variables?/i, "Variable")
|
||||
.replace("missing from database", "doesn't exist.");
|
||||
}
|
||||
|
||||
// all other specific error types
|
||||
if (errorType) {
|
||||
return reason
|
||||
.replace(/Secret variables?/i, `Variable used in ${errorType} `)
|
||||
.replace("missing from database", "doesn't exist.");
|
||||
}
|
||||
|
||||
// no spcial error type. return generic secret error message
|
||||
return reason
|
||||
.replace(/Secret variables?/i, "Variable")
|
||||
.replace("missing from database", "doesn't exist.");
|
||||
};
|
||||
Reference in New Issue
Block a user