From f70af1a455e84f3de982c81448205f739f563dbf Mon Sep 17 00:00:00 2001 From: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Date: Fri, 19 Nov 2021 18:25:48 -0500 Subject: [PATCH] [Fleet] Fix formatNonFatal error typings and avoid type error (#119203) (#119241) Co-authored-by: Nicolas Chaulet --- .../fleet/server/services/managed_package_policies.ts | 2 +- x-pack/plugins/fleet/server/services/setup.ts | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/x-pack/plugins/fleet/server/services/managed_package_policies.ts b/x-pack/plugins/fleet/server/services/managed_package_policies.ts index e78bc096b8711..c702cfe96d986 100644 --- a/x-pack/plugins/fleet/server/services/managed_package_policies.ts +++ b/x-pack/plugins/fleet/server/services/managed_package_policies.ts @@ -74,7 +74,7 @@ export const upgradeManagedPackagePolicies = async ( if (dryRunResults.hasErrors) { const errors = dryRunResults.diff ? dryRunResults.diff?.[1].errors - : dryRunResults.body?.message; + : [dryRunResults.body?.message]; appContextService .getLogger() diff --git a/x-pack/plugins/fleet/server/services/setup.ts b/x-pack/plugins/fleet/server/services/setup.ts index 1c84073552e57..d39a5f4473199 100644 --- a/x-pack/plugins/fleet/server/services/setup.ts +++ b/x-pack/plugins/fleet/server/services/setup.ts @@ -220,8 +220,15 @@ export function formatNonFatalErrors( name: e.error.name, message: e.error.message, }; - } else { + } else if ('errors' in e) { return e.errors.map((upgradePackagePolicyError: any) => { + if (typeof upgradePackagePolicyError === 'string') { + return { + name: 'SetupNonFatalError', + message: upgradePackagePolicyError, + }; + } + return { name: upgradePackagePolicyError.key, message: upgradePackagePolicyError.message,