Skip to content

Commit

Permalink
Use injected lib.handleEsError instead of importing it in Upgrade Ass…
Browse files Browse the repository at this point in the history
…istant API route handlers. (elastic#111067)
  • Loading branch information
cjcenizal authored and sabarasaba committed Oct 14, 2021
1 parent 94fb0d5 commit 05f1411
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
*/

import { kibanaResponseFactory } from 'src/core/server';

import { handleEsError } from '../shared_imports';
import { createMockRouter, MockRouter, routeHandlerContextMock } from './__mocks__/routes.mock';
import { createRequestMock } from './__mocks__/request.mock';

Expand Down Expand Up @@ -33,6 +35,7 @@ describe('ES deprecations API', () => {
mockRouter = createMockRouter();
routeDependencies = {
router: mockRouter,
lib: { handleEsError },
};
registerESDeprecationRoutes(routeDependencies);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@ import { versionCheckHandlerWrapper } from '../lib/es_version_precheck';
import { RouteDependencies } from '../types';
import { reindexActionsFactory } from '../lib/reindexing/reindex_actions';
import { reindexServiceFactory } from '../lib/reindexing';
import { handleEsError } from '../shared_imports';

export function registerESDeprecationRoutes({ router, licensing, log }: RouteDependencies) {
export function registerESDeprecationRoutes({
router,
lib: { handleEsError },
licensing,
log,
}: RouteDependencies) {
router.get(
{
path: `${API_BASE_PATH}/es_deprecations`,
Expand Down Expand Up @@ -50,8 +54,8 @@ export function registerESDeprecationRoutes({ router, licensing, log }: RouteDep
return response.ok({
body: status,
});
} catch (e) {
return handleEsError({ error: e, response });
} catch (error) {
return handleEsError({ error, response });
}
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
*/

import { kibanaResponseFactory, RequestHandler } from 'src/core/server';

import { handleEsError } from '../shared_imports';
import { createMockRouter, MockRouter, routeHandlerContextMock } from './__mocks__/routes.mock';
import { createRequestMock } from './__mocks__/request.mock';
import { registerMlSnapshotRoutes } from './ml_snapshots';
Expand All @@ -26,6 +28,7 @@ describe('ML snapshots APIs', () => {
mockRouter = createMockRouter();
routeDependencies = {
router: mockRouter,
lib: { handleEsError },
};
registerMlSnapshotRoutes(routeDependencies);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { IScopedClusterClient, SavedObjectsClientContract } from 'kibana/server'
import { API_BASE_PATH } from '../../common/constants';
import { MlOperation, ML_UPGRADE_OP_TYPE } from '../../common/types';
import { versionCheckHandlerWrapper } from '../lib/es_version_precheck';
import { handleEsError } from '../shared_imports';
import { RouteDependencies } from '../types';

const findMlOperation = async (
Expand Down Expand Up @@ -99,7 +98,7 @@ const verifySnapshotUpgrade = async (
}
};

export function registerMlSnapshotRoutes({ router }: RouteDependencies) {
export function registerMlSnapshotRoutes({ router, lib: { handleEsError } }: RouteDependencies) {
// Upgrade ML model snapshot
router.post(
{
Expand Down Expand Up @@ -147,8 +146,8 @@ export function registerMlSnapshotRoutes({ router }: RouteDependencies) {
status: body.completed === true ? 'complete' : 'in_progress',
},
});
} catch (e) {
return handleEsError({ error: e, response });
} catch (error) {
return handleEsError({ error, response });
}
}
)
Expand Down
3 changes: 3 additions & 0 deletions x-pack/plugins/upgrade_assistant/server/routes/status.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
*/

import { kibanaResponseFactory } from 'src/core/server';

import { handleEsError } from '../shared_imports';
import { createMockRouter, MockRouter, routeHandlerContextMock } from './__mocks__/routes.mock';
import { createRequestMock } from './__mocks__/request.mock';
import { registerUpgradeStatusRoute } from './status';
Expand All @@ -31,6 +33,7 @@ describe('Status API', () => {
mockRouter = createMockRouter();
routeDependencies = {
router: mockRouter,
lib: { handleEsError },
};
registerUpgradeStatusRoute(routeDependencies);
});
Expand Down
7 changes: 3 additions & 4 deletions x-pack/plugins/upgrade_assistant/server/routes/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ import { getESUpgradeStatus } from '../lib/es_deprecations_status';
import { versionCheckHandlerWrapper } from '../lib/es_version_precheck';
import { getKibanaUpgradeStatus } from '../lib/kibana_status';
import { RouteDependencies } from '../types';
import { handleEsError } from '../shared_imports';

export function registerUpgradeStatusRoute({ router }: RouteDependencies) {
export function registerUpgradeStatusRoute({ router, lib: { handleEsError } }: RouteDependencies) {
router.get(
{
path: `${API_BASE_PATH}/status`,
Expand Down Expand Up @@ -63,8 +62,8 @@ export function registerUpgradeStatusRoute({ router }: RouteDependencies) {
details: getStatusMessage(),
},
});
} catch (e) {
return handleEsError({ error: e, response });
} catch (error) {
return handleEsError({ error, response });
}
}
)
Expand Down

0 comments on commit 05f1411

Please sign in to comment.