Fleet UI: Helpful team agent errors (#8001)

This commit is contained in:
RachelElysia 2022-09-28 13:31:44 -04:00 committed by GitHub
parent 7356378d0f
commit 7cdc2e2027
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 10 deletions

View file

@ -0,0 +1 @@
* Global agent options renders backend errors in UI

View file

@ -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 (