Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fleet] Handle error correctly in fleet server host input on prem instructions #122341

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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