-
-
Notifications
You must be signed in to change notification settings - Fork 11k
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
AxiosError: options must be an object #5142
Comments
import axios from 'axios'
import { parse, stringify } from 'qs'
const axiosInstance = axios.create({
paramsSerializer: {
encode: parse,
serialize: stringify,
},
}) Should fix it |
Same issue as @ckvv , but solution above did not fix it for me. Everything still the same. |
It seems to work as expected https://codesandbox.io/s/axios-issue-5142-92zlpm?file=/src/index.js import axios from "axios";
import { stringify } from "qs";
const api = axios.create({
paramsSerializer: {
serialize: stringify // or (params) => Qs.stringify(params, {arrayFormat: 'brackets'})
}
});
const formData = new FormData();
formData.append("file", 123);
(async () => {
const { data } = await api.post("https://httpbin.org/post", formData, {
params: {
x: [1, 2, 3]
}
});
console.log("Echo:", data);
})(); |
This is the expected format from the assertOptions function |
Is issue has origin on new feature: #5113 |
This is clearly a breaking change, documentation should also be updated accordingly. |
That's exactly what was done. This interface has been refactored in 1.0.0-alpha.1 |
I'll double check the timing but I've been using this interface before v1 and it just broke with 1.1.3 today. |
Duplicate of axios/axios-docs#90 |
It's working after all, just had to tweak something in a custom middleware I had. Thanks @J3m5 for the tip. |
Line 47 in 9d4b016
The original spelling should be changed to const instance = Axios.create({
paramsSerializer: {
serialize: (params) => Qs.stringify(params, {arrayFormat: 'brackets'})
},
}); This is a breaking update, but the documentation doesn't say ,and it contains a previous wrong usage |
HI
here my axiosservice.js file looks like import axios, { isCancel, AxiosError } from 'axios';
import { qs, parse, stringify } from 'qs';
class AxiosService {
instance = axios.create({
paramsSerializer: {
serialize: (params) => Qs.stringify(params, { arrayFormat: 'brackets' })
}
});
requestInterceptor = this.instance.interceptors.request.use(
(config) => {
let accessToken = localStorage.getItem(SESSION_CONSTANTS.ACCESS_TOKEN);
config.headers[HTTP_HEADERS.AUTHORIZATION] = `bearer ${accessToken}`;
config.headers[HTTP_HEADERS.X_AUTH_TOKEN] = `${accessToken}`;
config.headers[HTTP_HEADERS.REQUEST_FROM] = `GUI`;
return config;
},
(err) => Promise.reject(err)
); anyway im missing anything here ? also tried below solution too class AxiosService {
instance = axios.create({
paramsSerializer: {
encode: parse,
serialize: stringify
}
}); |
working, but causing TypeScript issues. Any idea how to work around it? |
Hi @murbanowicz |
Thanks everyone! In my case, it works:
|
Seems to be because the config created by create is not being merged correctly
Describe the bug
To Reproduce
Code snippet
No response
Expected behavior
No response
Axios Version
v1.1.3
Adapter Version
No response
Browser
No response
Browser Version
No response
Node.js Version
No response
OS
No response
Additional Library Versions
No response
Additional context/Screenshots
No response
The text was updated successfully, but these errors were encountered: