Skip to content

Commit

Permalink
use default error handler in installPackageHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
John Schulz committed Sep 3, 2020
1 parent d7ad578 commit b94cd78
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 13 deletions.
2 changes: 1 addition & 1 deletion x-pack/plugins/ingest_manager/server/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class IngestManagerError extends Error {
}
}

export const getHTTPResponseCode = (error: IngestManagerError): number => {
const getHTTPResponseCode = (error: IngestManagerError): number => {
if (error instanceof RegistryError) {
return 502; // Bad Gateway
}
Expand Down
16 changes: 4 additions & 12 deletions x-pack/plugins/ingest_manager/server/routes/epm/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import {
getLimitedPackages,
getInstallationObject,
} from '../../services/epm/packages';
import { IngestManagerError, getHTTPResponseCode, defaultIngestErrorHandler } from '../../errors';
import { IngestManagerError, defaultIngestErrorHandler } from '../../errors';
import { splitPkgKey } from '../../services/epm/registry';

export const getCategoriesHandler: RequestHandler<
Expand Down Expand Up @@ -150,14 +150,10 @@ export const installPackageHandler: RequestHandler<
};
return response.ok({ body });
} catch (e) {
const defaultResult = await defaultIngestErrorHandler({ error: e, response });
if (e instanceof IngestManagerError) {
logger.error(e);
return response.customError({
statusCode: getHTTPResponseCode(e),
body: { message: e.message },
});
return defaultResult;
}

// if there is an unknown server error, uninstall any package assets
try {
const installedPkg = await getInstallationObject({ savedObjectsClient, pkgName });
Expand All @@ -168,11 +164,7 @@ export const installPackageHandler: RequestHandler<
} catch (error) {
logger.error(`could not remove failed installation ${error}`);
}
logger.error(e);
return response.customError({
statusCode: 500,
body: { message: e.message },
});
return defaultResult;
}
};

Expand Down

0 comments on commit b94cd78

Please sign in to comment.