fleet/frontend/pages/SoftwarePage/SoftwareAddPage/SoftwareCustomPackage/helpers.tsx
Jonathan Katz 941c49b84e
Filter errors that start with Couldn't add (#42764)
<!-- Add the related story/sub-task/bug number, like Resolves #123, or
remove if NA -->
**Related issue:** Resolves #42572

# Checklist for submitter

If some of the following don't apply, delete the relevant line.

- [ ] Changes file added for user-visible changes in `changes/`,
`orbit/changes/` or `ee/fleetd-chrome/changes`.
See [Changes
files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/guides/committing-changes.md#changes-files)
for more information.

## Testing

- [x] Added/updated automated tests
- [ ] Where appropriate, [automated tests simulate multiple hosts and
test for host
isolation](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/reference/patterns-backend.md#unit-testing)
(updates to one hosts's records do not affect another)

- [x] QA'd all new/changed functionality manually
2026-03-31 16:33:55 -04:00

79 lines
2.1 KiB
TypeScript

import React from "react";
import { isAxiosError } from "axios";
import { getErrorReason } from "interfaces/errors";
import { LEARN_MORE_ABOUT_BASE_LINK } from "utilities/constants";
import CustomLink from "components/CustomLink";
import { generateSecretErrMsg } from "pages/SoftwarePage/helpers";
import {
ADD_SOFTWARE_ERROR_PREFIX,
DEFAULT_ADD_SOFTWARE_ERROR_MESSAGE,
REQUEST_TIMEOUT_ERROR_MESSAGE,
ensurePeriod,
formatAlreadyAvailableInstallMessage,
} from "../helpers";
// eslint-disable-next-line import/prefer-default-export
export const getErrorMessage = (err: unknown) => {
const isTimeout =
isAxiosError(err) &&
(err.response?.status === 504 || err.response?.status === 408);
const reason = getErrorReason(err);
if (isTimeout) {
return REQUEST_TIMEOUT_ERROR_MESSAGE;
}
// software is already available for install
if (reason.toLowerCase().includes("already")) {
const alreadyAvailableMessage = formatAlreadyAvailableInstallMessage(
reason
);
if (alreadyAvailableMessage) {
return alreadyAvailableMessage;
}
}
if (reason.includes("Secret variable")) {
return generateSecretErrMsg(err);
}
if (reason.includes("Unable to extract necessary metadata")) {
return (
<>
{ADD_SOFTWARE_ERROR_PREFIX} Unable to extract necessary metadata.{" "}
<CustomLink
url={`${LEARN_MORE_ABOUT_BASE_LINK}/package-metadata-extraction`}
text="Learn more"
newTab
variant="flash-message-link"
/>
</>
);
}
if (reason.includes("not a valid .tar.gz archive")) {
return (
<>
This is not a valid .tar.gz archive.{" "}
<CustomLink
url={`${LEARN_MORE_ABOUT_BASE_LINK}/tarball-archives`}
text="Learn more"
newTab
variant="flash-message-link"
/>
</>
);
}
if (reason.startsWith("Couldn't add.")) {
return `${ensurePeriod(reason)}`;
}
if (reason) {
return `${ADD_SOFTWARE_ERROR_PREFIX} ${ensurePeriod(reason)}`;
}
return DEFAULT_ADD_SOFTWARE_ERROR_MESSAGE;
};