Skip to content

Commit

Permalink
Better handle non-available package registry
Browse files Browse the repository at this point in the history
  • Loading branch information
skh committed May 14, 2020
1 parent c0e67f7 commit 85398b7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
6 changes: 6 additions & 0 deletions x-pack/plugins/ingest_manager/server/routes/setup/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ export const ingestManagerSetupHandler: RequestHandler = async (context, request
body: { isInitialized: true },
});
} catch (e) {
if (e.isBoom) {
return response.customError({
statusCode: e.output.statusCode,
body: { message: e.output.payload.message },
});
}
return response.customError({
statusCode: 500,
body: { message: e.message },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,13 @@ export async function ensureInstalledPackage(options: {
if (installedPackage) {
return installedPackage;
}
// if the requested packaged was not found to be installed, try installing
try {
await installLatestPackage({
savedObjectsClient,
pkgName,
callCluster,
});
return await getInstallation({ savedObjectsClient, pkgName });
} catch (err) {
throw new Error(err.message);
}
// if the requested packaged was not found to be installed, install
await installLatestPackage({
savedObjectsClient,
pkgName,
callCluster,
});
return await getInstallation({ savedObjectsClient, pkgName });
}

export async function installPackage(options: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,22 @@
import Boom from 'boom';
import fetch, { Response } from 'node-fetch';
import { streamToString } from './streams';
import { appContextService } from '../..';

export async function getResponse(url: string): Promise<Response> {
const logger = appContextService.getLogger();
try {
const response = await fetch(url);
if (response.ok) {
return response;
} else {
logger.error(`Error connecting to package registry: ${response.statusText}`);
throw new Boom(response.statusText, { statusCode: response.status });
}
} catch (e) {
throw Boom.boomify(e);
const message = `Error connecting to package registry: ${e.message}`;
logger.error(message);
throw new Boom(message, { statusCode: 502 });
}
}

Expand Down

0 comments on commit 85398b7

Please sign in to comment.