Skip to content

Commit

Permalink
Correctly catch errors from _installPackage()
Browse files Browse the repository at this point in the history
  • Loading branch information
skh committed Apr 7, 2021
1 parent 7877613 commit 8bed5f9
Showing 1 changed file with 32 additions and 25 deletions.
57 changes: 32 additions & 25 deletions x-pack/plugins/fleet/server/services/epm/packages/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,29 +286,31 @@ async function installPackageFromRegistry({
const { paths, packageInfo } = await Registry.getRegistryPackage(pkgName, pkgVersion);

// try installing the package, if there was an error, call error handler and rethrow
try {
return _installPackage({
savedObjectsClient,
esClient,
installedPkg,
paths,
packageInfo,
installType,
installSource: 'registry',
}).then((assets) => {
// TODO: without the ts-ignore, TS complains about the type of the value of the returned InstallResult.status
// @ts-ignore
return _installPackage({
savedObjectsClient,
esClient,
installedPkg,
paths,
packageInfo,
installType,
installSource: 'registry',
})
.then((assets) => {
return { assets, status: 'installed', installType };
})
.catch(async (err: Error) => {
await handleInstallPackageFailure({
savedObjectsClient,
error: err,
pkgName,
pkgVersion,
installedPkg,
esClient,
});
return { error: err, installType };
});
} catch (e) {
await handleInstallPackageFailure({
savedObjectsClient,
error: e,
pkgName,
pkgVersion,
installedPkg,
esClient,
});
throw e;
}
} catch (e) {
return {
error: e,
Expand Down Expand Up @@ -361,7 +363,8 @@ async function installPackageByUpload({
version: packageInfo.version,
packageInfo,
});

// TODO: without the ts-ignore, TS complains about the type of the value of the returned InstallResult.status
// @ts-ignore
return _installPackage({
savedObjectsClient,
esClient,
Expand All @@ -370,9 +373,13 @@ async function installPackageByUpload({
packageInfo,
installType,
installSource,
}).then((assets) => {
return { assets, status: 'installed', installType };
});
})
.then((assets) => {
return { assets, status: 'installed', installType };
})
.catch(async (err: Error) => {
return { error: err, installType };
});
} catch (e) {
return { error: e, installType };
}
Expand Down

0 comments on commit 8bed5f9

Please sign in to comment.