Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport #6027 to 4.5 - Pass Transport object as the context when callWithRequest is asked to use a transport method #6483

Merged
merged 1 commit into from
Mar 9, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/plugins/elasticsearch/lib/call_with_request.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,21 @@ const _ = require('lodash');
const Promise = require('bluebird');
const Boom = require('boom');
const getBasicAuthRealm = require('./get_basic_auth_realm');
const toPath = require('lodash/internal/toPath');

module.exports = (client) => {
return (req, endpoint, params = {}) => {
if (req.headers.authorization) {
_.set(params, 'headers.authorization', req.headers.authorization);
}
const api = _.get(client, endpoint);
const path = toPath(endpoint);
const api = _.get(client, path);
let apiContext = _.get(client, path.slice(0, -1));
if (_.isEmpty(apiContext)) {
apiContext = client;
}
if (!api) throw new Error(`callWithRequest called with an invalid endpoint: ${endpoint}`);
return api.call(client, params)
return api.call(apiContext, params)
.catch((err) => {
if (err.status === 401) {
// TODO: The err.message is temporary until we have support for getting headers in the client.
Expand Down