Skip to content

Commit

Permalink
Merge pull request #77 from jtomasek/report-role-errors
Browse files Browse the repository at this point in the history
Report errors when setting role
  • Loading branch information
rawagner authored Jul 15, 2020
2 parents ab6a200 + 9ae0f8f commit 563ad80
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/components/hosts/RoleDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import { SimpleDropdown } from '../ui/SimpleDropdown';
import { patchCluster } from '../../api/clusters';
import { HOST_ROLES } from '../../config/constants';
import { updateCluster } from '../../features/clusters/currentClusterSlice';
import { handleApiError } from '../../api/utils';
import { handleApiError, getErrorMessage } from '../../api/utils';
import { AlertsContext } from '../AlertsContextProvider';

type RoleDropdownProps = {
host: Host;
Expand All @@ -15,6 +16,7 @@ export const RoleDropdown: React.FC<RoleDropdownProps> = ({ host }) => {
const { role, id, clusterId } = host;
const [isDisabled, setDisabled] = React.useState(false);
const dispatch = useDispatch();
const { addAlert } = React.useContext(AlertsContext);

const setRole = async (role?: string) => {
const params: ClusterUpdateParams = {};
Expand All @@ -24,7 +26,9 @@ export const RoleDropdown: React.FC<RoleDropdownProps> = ({ host }) => {
const { data } = await patchCluster(clusterId as string, params);
dispatch(updateCluster(data));
} catch (e) {
handleApiError(e);
handleApiError(e, () =>
addAlert({ title: 'Failed to set role', message: getErrorMessage(e) }),
);
}
setDisabled(false);
};
Expand Down

0 comments on commit 563ad80

Please sign in to comment.