From e5f7a644d61eb120ef45478c0fd61ef5e7f8b759 Mon Sep 17 00:00:00 2001 From: Paul Tavares Date: Wed, 9 Dec 2020 15:29:44 -0500 Subject: [PATCH] fix handling the API calls --- .../edit_package_policy_page/index.tsx | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/edit_package_policy_page/index.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/edit_package_policy_page/index.tsx index 5ecfd9b3f6b8e..26f99bd88a923 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/edit_package_policy_page/index.tsx +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/edit_package_policy_page/index.tsx @@ -93,16 +93,23 @@ export const EditPackagePolicyForm = memo<{ setIsLoadingData(true); setLoadingError(undefined); try { - const { data: packagePolicyData } = await sendGetOnePackagePolicy(packagePolicyId); + const { + data: packagePolicyData, + error: packagePolicyError, + } = await sendGetOnePackagePolicy(packagePolicyId); - if (!packagePolicyData?.item.policy_id) { - throw new window.Error(`Agent Policy ID missing in package policy ${packagePolicyId}`); + if (packagePolicyError) { + throw packagePolicyError; } - const { data: agentPolicyData } = await sendGetOneAgentPolicy( - packagePolicyData.item.policy_id + const { data: agentPolicyData, error: agentPolicyError } = await sendGetOneAgentPolicy( + packagePolicyData!.item.policy_id ); + if (agentPolicyError) { + throw agentPolicyError; + } + if (agentPolicyData?.item) { setAgentPolicy(agentPolicyData.item); }