Pass Transport object as the context when callWithRequest is asked to use a transport method#6027
Merged
spalger merged 1 commit intoelastic:masterfrom Feb 1, 2016
Merged
Conversation
Contributor
There was a problem hiding this comment.
I'd feel a lot better about this if it used var toPath = require('lodash/internal/toPath'); to parse the path and then did something like this:
const path = toPath(endpoint);
const api = get(client, path);
const apiContext = get(client, path.slice(0, -1), client);
return api.call(apiContext, ...… when called normally instead of assuming client is the context for everything
21c4660 to
580ff60
Compare
Contributor
Author
|
@spalger updated the commit based on your advice. I had to add a separate isEmpty check instead of providing client as a default since slice returns an empty array, not undefined when it's range doesn't include any elements. Please take another quick look! |
Contributor
There was a problem hiding this comment.
I'm not sure why you can't use _.get()'s third argument here.
_.get({ fakeClient: true }, []) // returns undefined
_.get({ fakeClient: true }, [], 'pasta') // returns 'pasta'
_.get(client, path.slice(0, -1), client); // returns client when path is [], or doesn't resolve to anything for some reason
spalger
added a commit
that referenced
this pull request
Feb 1, 2016
Pass Transport object as the context when callWithRequest is asked to use a transport method
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
callWithRequest assumes every elasticsearch.js API method needs the client object as its context, but this isn't the case. Transport.request expects the transport object itself as context.