mirror of
https://github.com/fleetdm/fleet
synced 2026-05-24 09:28:54 +00:00
Fleet UI: Helpful team agent errors (#8001)
This commit is contained in:
parent
7356378d0f
commit
7cdc2e2027
2 changed files with 16 additions and 10 deletions
1
changes/issue-7997-better-agent-options-error
Normal file
1
changes/issue-7997-better-agent-options-error
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
* Global agent options renders backend errors in UI
|
||||||
|
|
@ -4,6 +4,7 @@ import { useErrorHandler } from "react-error-boundary";
|
||||||
import yaml from "js-yaml";
|
import yaml from "js-yaml";
|
||||||
|
|
||||||
import { NotificationContext } from "context/notification";
|
import { NotificationContext } from "context/notification";
|
||||||
|
import { IApiError } from "interfaces/errors";
|
||||||
import { ITeam } from "interfaces/team";
|
import { ITeam } from "interfaces/team";
|
||||||
import endpoints from "utilities/endpoints";
|
import endpoints from "utilities/endpoints";
|
||||||
import teamsAPI, { ILoadTeamsResponse } from "services/entities/teams";
|
import teamsAPI, { ILoadTeamsResponse } from "services/entities/teams";
|
||||||
|
|
@ -30,6 +31,7 @@ const AgentOptionsPage = ({
|
||||||
const teamIdFromURL = parseInt(team_id, 10);
|
const teamIdFromURL = parseInt(team_id, 10);
|
||||||
const { renderFlash } = useContext(NotificationContext);
|
const { renderFlash } = useContext(NotificationContext);
|
||||||
|
|
||||||
|
const [teamName, setTeamName] = useState("");
|
||||||
const [formData, setFormData] = useState<{ osquery_options?: string }>({});
|
const [formData, setFormData] = useState<{ osquery_options?: string }>({});
|
||||||
const handlePageError = useErrorHandler();
|
const handlePageError = useErrorHandler();
|
||||||
|
|
||||||
|
|
@ -45,6 +47,7 @@ const AgentOptionsPage = ({
|
||||||
setFormData({
|
setFormData({
|
||||||
osquery_options: yaml.dump(selected.agent_options),
|
osquery_options: yaml.dump(selected.agent_options),
|
||||||
});
|
});
|
||||||
|
setTeamName(selected.name);
|
||||||
} else {
|
} else {
|
||||||
handlePageError({ status: 404 });
|
handlePageError({ status: 404 });
|
||||||
}
|
}
|
||||||
|
|
@ -62,16 +65,18 @@ const AgentOptionsPage = ({
|
||||||
return renderFlash("error", error.reason);
|
return renderFlash("error", error.reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
osqueryOptionsAPI
|
||||||
await osqueryOptionsAPI.update(
|
.update(updatedForm, TEAMS_AGENT_OPTIONS(teamIdFromURL))
|
||||||
updatedForm,
|
.then(() => {
|
||||||
TEAMS_AGENT_OPTIONS(teamIdFromURL)
|
renderFlash("success", "Successfully saved agent options");
|
||||||
);
|
})
|
||||||
return renderFlash("success", "Successfully saved agent options");
|
.catch((response: { data: IApiError }) => {
|
||||||
} catch (response) {
|
console.error(response);
|
||||||
console.error(response);
|
return renderFlash(
|
||||||
return renderFlash("error", "Could not save agent options");
|
"error",
|
||||||
}
|
`Could not update ${teamName} team agent options. ${response.data.errors[0].reason}`
|
||||||
|
);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue