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); }