mirror of
https://github.com/fleetdm/fleet
synced 2026-04-21 13:37:30 +00:00
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
This commit is contained in:
parent
e35d07c96d
commit
941c49b84e
3 changed files with 58 additions and 1 deletions
1
changes/42572-fix-duplicate-text
Normal file
1
changes/42572-fix-duplicate-text
Normal file
|
|
@ -0,0 +1 @@
|
|||
- Fixed duplicate text in error message when script validation fails when adding a custom package
|
||||
|
|
@ -0,0 +1,53 @@
|
|||
import { getErrorMessage } from "./helpers";
|
||||
|
||||
jest.mock("axios", () => {
|
||||
const actual = jest.requireActual("axios");
|
||||
return {
|
||||
...actual,
|
||||
isAxiosError: () => true,
|
||||
};
|
||||
});
|
||||
|
||||
describe("getErrorMessage", () => {
|
||||
it("returns message for pending install/uninstall error", () => {
|
||||
const err = {
|
||||
response: {
|
||||
status: 400,
|
||||
data: {
|
||||
errors: [
|
||||
{
|
||||
name: "Error",
|
||||
reason:
|
||||
"Couldn't install. Host already has a pending install/uninstall for this installer.",
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
expect(getErrorMessage(err)).toBe(
|
||||
"Couldn't add. Couldn't install. Host already has a pending install/uninstall for this installer."
|
||||
);
|
||||
});
|
||||
|
||||
it("returns message for script validation error", () => {
|
||||
const err = {
|
||||
response: {
|
||||
status: 400,
|
||||
data: {
|
||||
errors: [
|
||||
{
|
||||
name: "Error",
|
||||
reason:
|
||||
"Couldn't add. Script validation failed: Script is too large. It's limited to 500,000 characters (approximately 10,000 lines).",
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
expect(getErrorMessage(err)).toBe(
|
||||
"Couldn't add. Script validation failed: Script is too large. It's limited to 500,000 characters (approximately 10,000 lines)."
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
@ -22,7 +22,6 @@ export const getErrorMessage = (err: unknown) => {
|
|||
isAxiosError(err) &&
|
||||
(err.response?.status === 504 || err.response?.status === 408);
|
||||
const reason = getErrorReason(err);
|
||||
|
||||
if (isTimeout) {
|
||||
return REQUEST_TIMEOUT_ERROR_MESSAGE;
|
||||
}
|
||||
|
|
@ -68,6 +67,10 @@ export const getErrorMessage = (err: unknown) => {
|
|||
);
|
||||
}
|
||||
|
||||
if (reason.startsWith("Couldn't add.")) {
|
||||
return `${ensurePeriod(reason)}`;
|
||||
}
|
||||
|
||||
if (reason) {
|
||||
return `${ADD_SOFTWARE_ERROR_PREFIX} ${ensurePeriod(reason)}`;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue