question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Doesn't append instance parameters

See original GitHub issue

#### Summary I’m trying to create a new axios instance with default params assigned. The baseURL is appended, but not the params:

I have a static HTTP class that I clone with options for an axios instance:

static create(options: Object = {}): Object {
    // See comment for class cloning <https://stackoverflow.com/a/41474987>
    const clone = Object.assign(Object.create(this), this)

    return Object.defineProperty(clone, 'axios', {
      enumerable: false,
      configurable: false,
      writable: false,
      value: axios.create(options)
    })
  }

And then I have a TMDbProvider class that uses the cloned class from HTTP.

constructor(state) {
    this.http = HTTP.create({
      baseURL: `${config.TMDB.API}/3`,
      params: {
        api_key: config.TMDB.KEY,
        language: state.saved.prefs.iso4,
        append_to_response: 'external_ids,videos'
      }
    })
  }

Example of a get function in the HTTP class:

  static get(url: String, params: Object): Promise {
    return this.axios.get(url, { params })
      .then(res => res.data)
  }

As stated above in the summary, the default params doesn’t get attached as shown below. /home/sentinel/git/venobo-redux/node_modules/axios/lib/adapters/xhr.js:178 GET https://api.themoviedb.org/3/movie/76341 401 (Unauthorized)

But if I console.log the clone.axios.defaults object then the params are assigned.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:4
  • Comments:6

github_iconTop GitHub Comments

7reactions
jurpeedurpcommented, Jun 19, 2019

A temporary workaround is to use an interceptor:

const client = axios.create()

client.interceptors.request.use((config) => ({
    ...config,
    params: {
        api_key: 'xxx',
        ...config.params
    }
}))
6reactions
cfjedimastercommented, Mar 16, 2018

I just ran into this as well and was pretty surprised. Using default params for APIs is pretty common. Any simple workaround (outside of adding it to my get()) call?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why does not the + operator change a list while .append() does?
So in a function the adding a 6 to the set doesn't show but it does when not in a function? No, that...
Read more >
Visibility parameter of a family does not work in a project in Revit
Causes: The instance parameter of the family is not properly associated with the visibility parameter of the specific element inside the family.
Read more >
Python's .append(): Add Items to Your Lists in Place
append () will place new items in the available space. Lists are sequences that can hold different data types and Python objects, so...
Read more >
Element.append() - Web APIs - MDN Web Docs
The Element.append() method inserts a set of Node objects or string objects after the last child of the Element. String objects are inserted ......
Read more >
Resolve the "Parameter validation failed" error in AWS ...
As a parameter in a child stack. The error occurs when the value of the child stack that's passed from the parent stack...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found