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

How can I get the third parameter in the interceptor? #2216

Closed
kdydesign opened this issue Jun 10, 2019 · 7 comments
Closed

How can I get the third parameter in the interceptor? #2216

kdydesign opened this issue Jun 10, 2019 · 7 comments

Comments

@kdydesign
Copy link

kdydesign commented Jun 10, 2019

  • Axios Version : 0.19.x

If a third parameter is sent when a post request is requested, the parameter sent in the 'config' factor of 'request interceptor' cannot be found.

ex)

axios.post('url', {parameter}, {options})

...

axios.interceptors.request.use(config => {
config.options // not found
})

It was possible at 0.18.x, but not at 0.19.x. How can I get a third parameter from the interceptor?

@ghost
Copy link

ghost commented Jun 14, 2019

Third parameters used to be merged into config object.
In v0.19, either adding custom props to config (axios.request) or to "options" third parameter for shortcuts methods do not work anymore.

Could you please restore v0.18 behavior ?

Thanks !

@kevinkiel
Copy link

We've got the same problems we are using it for a custom error handler but since the update tot 0.19.x its not working anymore. @axios can you please fix this feature?

@neeonline
Copy link

Same issue here. Before this version (v0.19) was possible to add custom parameters to the config object.

Any updates on this?

@KarlBao
Copy link

KarlBao commented Jun 18, 2019

The same here! Hope custom parameters could be supported as it used to be.

@Peek-A-Booo
Copy link

Same issue here. Before this version (v0.19) was possible to add custom parameters to the config object.

Any updates on this?

In v0.19 , it add a 'mergeConfig' function in /lib/axios.js. It will only allow some standard keywords to the config , maybe for "Consistent coding style"

@jeremyrambo
Copy link

jeremyrambo commented Jun 25, 2019

Same issue here. In v0.18 I would pass in "custom" configuration that would then be intercepted in a request interceptor to apply the correct headers. We are doing this as we migrate major versions of our back end.

Here is an example of the request:

const response = await Vue.axios.get(`${_baseUrl}/${companyId}/employees`, { acceptVersion: '1.0.0', adminVersion: 2 } )
return response.data.employees

Then in our request interceptor we have the following code:

axios.interceptors.request.use( config => {
	config.headers = Object.assign(config.headers || {}, {
		'X-Admin-Version': config.adminVersion || 1, // Temporary Default, this should be 2
		'Accept-Version': config.acceptVersion || '2.0.0' // Temporary Default, this should be 2.0.0
	})
	config.withCredentials = true
	return config
})

Once we upgraded to v0.19 the config options for adminVersion and acceptVersion have been stripped.

From what I can tell, the merging of the config was the culprit in line 37 of the core/Axios.js file.

Are there plans to restore the functionality or should we be planning going a different route? If you don't plan on restoring the functionality, is there a way to get another hook in place that will let me modify the config before you run the merge?

Thanks in advance.

@rafaelrenanpacheco
Copy link
Contributor

#2207 will fix this once it is merged.

@axios axios locked and limited conversation to collaborators May 22, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants