diff --git a/x-pack/server/lib/create_router/call_with_request_factory/call_with_request_factory.js b/x-pack/server/lib/create_router/call_with_request_factory/call_with_request_factory.js index 7359a831994f9..a7703335f0c90 100644 --- a/x-pack/server/lib/create_router/call_with_request_factory/call_with_request_factory.js +++ b/x-pack/server/lib/create_router/call_with_request_factory/call_with_request_factory.js @@ -4,15 +4,9 @@ * you may not use this file except in compliance with the Elastic License. */ -import { once } from 'lodash'; - -const callWithRequest = once(server => { - const cluster = server.plugins.elasticsearch.getCluster('data'); - return cluster.callWithRequest; -}); - export const callWithRequestFactory = (server, request) => { + const { callWithRequest } = server.plugins.elasticsearch.getCluster('data'); return (...args) => { - return callWithRequest(server)(request, ...args); + return callWithRequest(request, ...args); }; }; diff --git a/x-pack/server/lib/create_router/index.js b/x-pack/server/lib/create_router/index.js index 56353dc45fe74..74ec7dc936740 100644 --- a/x-pack/server/lib/create_router/index.js +++ b/x-pack/server/lib/create_router/index.js @@ -16,13 +16,13 @@ export const createRouter = (server, pluginId, apiBasePath = '') => { const requestHandler = (handler) => async (request, h) => { const callWithRequest = callWithRequestFactory(server, request); try { - return handler(request, callWithRequest, h); + return await handler(request, callWithRequest, h); } catch (err) { if (isEsError(err)) { - throw wrapEsError(err); + return wrapEsError(err); } - throw wrapUnknownError(err); + return wrapUnknownError(err); } }; diff --git a/x-pack/server/lib/create_router/license_pre_routing_factory/license_pre_routing_factory.js b/x-pack/server/lib/create_router/license_pre_routing_factory/license_pre_routing_factory.js index de951d40c0b98..43ff9aa231889 100644 --- a/x-pack/server/lib/create_router/license_pre_routing_factory/license_pre_routing_factory.js +++ b/x-pack/server/lib/create_router/license_pre_routing_factory/license_pre_routing_factory.js @@ -4,12 +4,11 @@ * you may not use this file except in compliance with the Elastic License. */ -import { once } from 'lodash'; import { wrapCustomError } from '../error_wrappers'; import { LICENSE_STATUS_VALID } from '../../../../common/constants'; export const licensePreRoutingFactory = (server, pluginId) => { - const licensePreRouting = () => { + return () => { // License checking and enable/disable logic const xpackMainPlugin = server.plugins.xpack_main; const licenseCheckResults = xpackMainPlugin.info.feature(pluginId).getLicenseCheckResults(); @@ -21,6 +20,4 @@ export const licensePreRoutingFactory = (server, pluginId) => { return null; }; - - return () => once(licensePreRouting)(); };