Skip to content

Commit

Permalink
getSavedObjectsClient may be null, specifically during tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jloleysens committed Nov 12, 2019
1 parent c0d123a commit 1b229f5
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ export const createRequestShim = (req: Request): RequestShim => {
headers: req.headers,
payload: req.payload,
params: req.params,
getSavedObjectsClient: req.getSavedObjectsClient.bind(req),
getSavedObjectsClient: req.getSavedObjectsClient ? req.getSavedObjectsClient.bind(req) : null,
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ export function registerReindexIndicesRoutes(
},
async handler(request) {
const reqShim = createRequestShim(request);
if (!reqShim.getSavedObjectsClient) {
// May be null under certain conditions, probably in tests.
throw new Error('Could not find SavedObjectsClient getter.');
}
const client = reqShim.getSavedObjectsClient();
const { indexName } = reqShim.params;
const callCluster = callWithRequest.bind(null, reqShim) as CallCluster;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/
import { Legacy } from 'kibana';
import { SavedObjectsClientContract } from 'kibana/server';
import { ServerRoute } from 'hapi';
import { ElasticsearchPlugin } from 'src/legacy/core_plugins/elasticsearch';
import { XPackMainPlugin } from '../../../xpack_main/xpack_main';
Expand Down Expand Up @@ -31,5 +32,5 @@ export interface RequestShim {
headers: { [key: string]: string };
payload: any;
params: any;
getSavedObjectsClient: any;
getSavedObjectsClient: (() => SavedObjectsClientContract) | null;
}

0 comments on commit 1b229f5

Please sign in to comment.