mirror of
https://github.com/fleetdm/fleet
synced 2026-05-21 07:58:31 +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 { NotificationContext } from "context/notification";
|
||||
import { IApiError } from "interfaces/errors";
|
||||
import { ITeam } from "interfaces/team";
|
||||
import endpoints from "utilities/endpoints";
|
||||
import teamsAPI, { ILoadTeamsResponse } from "services/entities/teams";
|
||||
|
|
@ -30,6 +31,7 @@ const AgentOptionsPage = ({
|
|||
const teamIdFromURL = parseInt(team_id, 10);
|
||||
const { renderFlash } = useContext(NotificationContext);
|
||||
|
||||
const [teamName, setTeamName] = useState("");
|
||||
const [formData, setFormData] = useState<{ osquery_options?: string }>({});
|
||||
const handlePageError = useErrorHandler();
|
||||
|
||||
|
|
@ -45,6 +47,7 @@ const AgentOptionsPage = ({
|
|||
setFormData({
|
||||
osquery_options: yaml.dump(selected.agent_options),
|
||||
});
|
||||
setTeamName(selected.name);
|
||||
} else {
|
||||
handlePageError({ status: 404 });
|
||||
}
|
||||
|
|
@ -62,16 +65,18 @@ const AgentOptionsPage = ({
|
|||
return renderFlash("error", error.reason);
|
||||
}
|
||||
|
||||
try {
|
||||
await osqueryOptionsAPI.update(
|
||||
updatedForm,
|
||||
TEAMS_AGENT_OPTIONS(teamIdFromURL)
|
||||
);
|
||||
return renderFlash("success", "Successfully saved agent options");
|
||||
} catch (response) {
|
||||
console.error(response);
|
||||
return renderFlash("error", "Could not save agent options");
|
||||
}
|
||||
osqueryOptionsAPI
|
||||
.update(updatedForm, TEAMS_AGENT_OPTIONS(teamIdFromURL))
|
||||
.then(() => {
|
||||
renderFlash("success", "Successfully saved agent options");
|
||||
})
|
||||
.catch((response: { data: IApiError }) => {
|
||||
console.error(response);
|
||||
return renderFlash(
|
||||
"error",
|
||||
`Could not update ${teamName} team agent options. ${response.data.errors[0].reason}`
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
|
|
|
|||
Loading…
Reference in a new issue