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:
- Created 6 years ago
- Reactions:4
- Comments:6
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
A temporary workaround is to use an interceptor:
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?