[Fleet] Handle error in duplicate policy in the UI (#121538)

This commit is contained in:
Nicolas Chaulet 2021-12-20 08:07:57 -05:00 committed by GitHub
parent c4585b3382
commit 9006de6dee
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 24 deletions

View file

@ -58,33 +58,33 @@ export const AgentPolicyCopyProvider: React.FunctionComponent<Props> = ({ childr
const copyAgentPolicy = async () => {
setIsLoading(true);
try {
const { data } = await sendCopyAgentPolicy(agentPolicy!.id, newAgentPolicy!);
const { data, error } = await sendCopyAgentPolicy(agentPolicy!.id, newAgentPolicy!);
if (data) {
notifications.toasts.addSuccess(
i18n.translate('xpack.fleet.copyAgentPolicy.successNotificationTitle', {
defaultMessage: 'Agent policy duplicated',
})
);
if (onSuccessCallback.current) {
onSuccessCallback.current(data.item);
}
} else {
notifications.toasts.addDanger(
i18n.translate('xpack.fleet.copyAgentPolicy.failureNotificationTitle', {
defaultMessage: "Error duplicating agent policy '{id}'",
values: { id: agentPolicy!.id },
})
);
if (error) {
throw error;
}
} catch (e) {
notifications.toasts.addDanger(
i18n.translate('xpack.fleet.copyAgentPolicy.fatalErrorNotificationTitle', {
defaultMessage: 'Error duplicating agent policy',
if (!data) {
throw new Error('Error duplicating agent policy: no data');
}
notifications.toasts.addSuccess(
i18n.translate('xpack.fleet.copyAgentPolicy.successNotificationTitle', {
defaultMessage: 'Agent policy duplicated',
})
);
closeModal();
if (onSuccessCallback.current) {
onSuccessCallback.current(data.item);
}
} catch (e) {
setIsLoading(false);
notifications.toasts.addError(e, {
title: i18n.translate('xpack.fleet.copyAgentPolicy.fatalErrorNotificationTitle', {
defaultMessage: 'Error duplicating agent policy',
}),
});
}
closeModal();
};
const renderModal = () => {

View file

@ -10230,7 +10230,6 @@
"xpack.fleet.copyAgentPolicy.confirmModal.defaultNewPolicyName": "{name}(コピー)",
"xpack.fleet.copyAgentPolicy.confirmModal.newDescriptionLabel": "説明",
"xpack.fleet.copyAgentPolicy.confirmModal.newNameLabel": "新しいポリシー名",
"xpack.fleet.copyAgentPolicy.failureNotificationTitle": "エージェントポリシー'{id}'の複製エラー",
"xpack.fleet.copyAgentPolicy.fatalErrorNotificationTitle": "エージェントポリシーの複製エラー",
"xpack.fleet.copyAgentPolicy.successNotificationTitle": "エージェントポリシーが複製されました",
"xpack.fleet.createAgentPolicy.cancelButtonLabel": "キャンセル",

View file

@ -10325,7 +10325,6 @@
"xpack.fleet.copyAgentPolicy.confirmModal.defaultNewPolicyName": "{name}(副本)",
"xpack.fleet.copyAgentPolicy.confirmModal.newDescriptionLabel": "描述",
"xpack.fleet.copyAgentPolicy.confirmModal.newNameLabel": "新策略名称",
"xpack.fleet.copyAgentPolicy.failureNotificationTitle": "复制代理策略“{id}”时出错",
"xpack.fleet.copyAgentPolicy.fatalErrorNotificationTitle": "复制代理策略时出错",
"xpack.fleet.copyAgentPolicy.successNotificationTitle": "已复制代理策略",
"xpack.fleet.createAgentPolicy.cancelButtonLabel": "取消",