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