Skip to content

Commit

Permalink
[Fleet] Handle error correctly in fleet server host input on prem ins…
Browse files Browse the repository at this point in the history
…tructions (#122341)
  • Loading branch information
nchaulet authored Jan 5, 2022
1 parent 673c88f commit 1c95b53
Showing 1 changed file with 15 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -295,20 +295,15 @@ export const useFleetServerInstructions = (policyId?: string) => {

const addFleetServerHost = useCallback(
async (host: string) => {
try {
await sendPutSettings({
fleet_server_hosts: [host, ...(settings?.item.fleet_server_hosts || [])],
});
await refreshSettings();
} catch (err) {
notifications.toasts.addError(err, {
title: i18n.translate('xpack.fleet.fleetServerSetup.errorAddingFleetServerHostTitle', {
defaultMessage: 'Error adding Fleet Server host',
}),
});
const res = await sendPutSettings({
fleet_server_hosts: [host, ...(settings?.item.fleet_server_hosts || [])],
});
if (res.error) {
throw res.error;
}
await refreshSettings();
},
[refreshSettings, notifications.toasts, settings?.item.fleet_server_hosts]
[refreshSettings, settings?.item.fleet_server_hosts]
);

return {
Expand Down Expand Up @@ -427,6 +422,7 @@ export const AddFleetServerHostStepContent = ({
const [isLoading, setIsLoading] = useState(false);
const [fleetServerHost, setFleetServerHost] = useState('');
const [error, setError] = useState<undefined | string>();
const { notifications } = useStartServices();

const { getHref } = useLink();

Expand Down Expand Up @@ -457,10 +453,16 @@ export const AddFleetServerHostStepContent = ({
} else {
setCalloutHost('');
}
} catch (err) {
notifications.toasts.addError(err, {
title: i18n.translate('xpack.fleet.fleetServerSetup.errorAddingFleetServerHostTitle', {
defaultMessage: 'Error adding Fleet Server host',
}),
});
} finally {
setIsLoading(false);
}
}, [fleetServerHost, addFleetServerHost, validate]);
}, [fleetServerHost, addFleetServerHost, validate, notifications.toasts]);

const onChange = useCallback(
(e: React.ChangeEvent<HTMLInputElement>) => {
Expand Down

0 comments on commit 1c95b53

Please sign in to comment.