Skip to content

Commit

Permalink
Fix common router request handler issue (#32275) (#32598)
Browse files Browse the repository at this point in the history
* Add `await` to common router request handler

* Remove once() from common license checker and call with request factories
  • Loading branch information
jen-huang authored Mar 6, 2019
1 parent 5e81271 commit 1906fbe
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
};
6 changes: 3 additions & 3 deletions x-pack/server/lib/create_router/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -21,6 +20,4 @@ export const licensePreRoutingFactory = (server, pluginId) => {

return null;
};

return () => once(licensePreRouting)();
};

0 comments on commit 1906fbe

Please sign in to comment.