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

Pass timeout param to request.js #27

Closed
wants to merge 1 commit into from
Closed

Conversation

jarocks
Copy link

@jarocks jarocks commented Jul 20, 2020

Solves for the problem brought up in issue #26

Fixes #26

@cla-checker-service
Copy link

cla-checker-service bot commented Jul 20, 2020

❌ Author of the following commits did not sign a Contributor Agreement:
2443921

Please, read and sign the above mentioned agreement if you want to contribute to this project

@JasonStoltz
Copy link
Member

Thanks, I'll review this today. Please sign the CLA

@jarocks
Copy link
Author

jarocks commented Jul 21, 2020

I signed it yesterday, am not sure why the bot is still marking it as incomplete.

Copy link
Member

@JasonStoltz JasonStoltz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made one comment about the current API.

Additionally, the way people typically instantiate the client is with the AppSearchClient class, which means you'd need to update that as well to accept a timeout.

That's a little tricky, since we already have an optional third parameter.

I suppose we could change the third parameter to be a configuration object, with backwards compatible support for the string baseUrlFn.

  constructor(accountHostKey, apiKey, options = {}) {
    const barUrlFn = options.baseUrlFn || DEFAULT_BASE_URL_FN
    const baseUrl = baseUrlFn(accountHostKey)
    const { timeout } = options
    this.client = new Client(apiKey, baseUrl, options)
  }

We'd also need to update the README to show the new usage.

const client = new AppSearchClient(undefined, apiKey, { baseUrlFn })

And also a separate example showing setting a timeout

const client = new AppSearchClient(undefined, apiKey, { baseUrlFn, timeout })

Does that make sense?

@@ -42,11 +42,12 @@ function getErrorMessages(responseBody) {
}
}
class Client {
constructor(apiKey, baseUrl) {
constructor(apiKey, baseUrl, timeout) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you so much for making this change. This is great. Could you change this to be an optional config object? That just future proofs this method in case we have additional configuration needs.

Suggested change
constructor(apiKey, baseUrl, timeout) {
constructor(apiKey, baseUrl, { timeout } = {}) {

Then later:

this.requestConfig = { timeout };

And finally:

_jsonRequest(method, path, params) {
    return this._wrap({
      method: method,
      url: `${this.baseUrl}${path}`,
      json: params,
      auth: {
        bearer: this.apiKey
      },
      headers: {
        'X-Swiftype-Client': this.clientName,
        'X-Swiftype-Client-Version': this.clientVersion,
        'Content-Type': 'application/json'
      },
      { ...this.requestConfig }
    })
  }

@JasonStoltz
Copy link
Member

Also, see if you can sign the CLA one more time ... maybe you mistyped your Github name or email? If that doesn't work we might need to open a new PR. Sorry for the inconvenience. Again, I really appreciate this PR.

@jarocks jarocks closed this Oct 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

No support to handle timeouts
2 participants