-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
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
Axios config headers causes requests to fail with ERR_INVALID_CHAR #5089
Comments
I am having the same issue, had to downgrade to version below 1.0.0 |
Thank you for bringing this up @lohart13, we have the exact same issue. |
Experiencing the same issue, v1.1.3, tho tested on browser(firefox) / react, the error i got: // [ ... ]
axiosInstance.interceptors.response.use(
undefined,
(err) => {
// [ ... ]
const config = err.config;
// config.headers is possibly undefined
config.headers = JSON.parse(JSON.stringify(config.headers || {})) as RawAxiosRequestHeaders;
// [ ... ]
return axiosInstance(config);
},
); when checked {
"Content-Type": null,
Symbol(defaults): Object { Accept: "application/json, text/plain, */*" },
// [ ... ]
} transformed to: {
Accept: "application/json, text/plain, */*",
// [ ... ]
} not sure where the |
Thank you for this workaround....i think i debugged this for 3 hours thinking I'm doing something wrong |
same issue here, but for me this error doesn't appear every single time when making the API call.. anyway, is anyone working on a fix yet? |
Im seeing this when running tests in jest. |
Having the same problem with the latest version of axios (1.1.3), when trying to retry a request. config.headers = JSON.parse(JSON.stringify(config.headers || {})) as RawAxiosRequestHeaders; Did the trick as a temporary workaround. |
Hi everyone. it('should not fail during retries request with headers', function (done) {
const retries = 100;
let resRetry = 0;
server = http.createServer(function (req, res) {
res.writeHead(resRetry < retries ? 404 : 200);
resRetry++;
res.end();
}).listen(4444, function () {
const api = axios.create({ baseURL: 'http://localhost:4444' });
let reqConfig;
let reqRetry = 0;
api.interceptors.request.use((config) => {
config.headers.Authorization = 'xxx';
return config;
});
api.interceptors.request.use((config) => {
reqConfig = config;
return config;
});
api.interceptors.response.use(null, async (error) => {
if (reqRetry < retries + 1) {
reqRetry++;
return api(reqConfig);
}
return Promise.reject(error);
});
api.get('/')
.then(() => done())
.catch((e) => done(e))
});
}); |
I hit the same issue. Tried the interceptor workaround but it didn't seem to work for me (other kinds of errors got thrown inside the interceptor). I was probably doing it wrong, but needed to resolve quickly so I switched to the package |
@EugeneSnikhovskiy maybe the api.interceptors.request.use((config) => {
reqConfig = config;
return config;
}); Doesn’t get triggered. Either way try assigning the |
@AntanasGa thanks for response. I tested your suggestion and even try to use axios-retry lib in unit test (with same code as in my project) but test is always succeed |
I nearly spent a day around this and thought I might be doing something wrong. I was trying to retry the request if the axios timeout set is too small for my async request interceptor to attach some data to my request headers. This hack saved the day. Thanks 🙏🏽 |
do axios team have plan to fix this? |
temporarily fixed with |
Having the same issue with axios-retry library! Came up with the following fix.
|
This appears to be fixed in |
Still getting the issues in ^1.3.4 version. |
same challenge, header had a newline character(\n), remove any existence of \n fixed the issue. |
I have tried several versions of axios from |
@simonklimek have you tried ? |
@mikemasam I'm not sure where to modify the headers. Should I modify headers as a request interceptor or use this replace code somwhere else? my httpClient.js looks as follows:
config.js
authInterceptor.js
much appreciated your help |
My working solution I came up with is replacing object constructor for headers
|
It seem you had a different issue, maybe
Yanked all new lines since i was reading token from a file edited with a notepad gui application. |
Describe the bug
When using the
error.config
property of an AxiosError to resubmit a request, the below error is thrown. Prior to version 1.x, this solution worked perfectly.After looking through the code, it appears that there are two issues at play.
The first one is that when an existing instance of AxiosHeaders is passed as a parameter to the new AxiosHeaders function, the headers from the previous instance are not correctly read.
The second issue is there when the config passed to the axios function is merged with the default headers, the output header object fails to merge with the default header object as the header object in the config passed to the axios function is an instance of AxiosHeaders not a plain object.
Sample header instance from the error.config.headers
Sample header instance that causes the error to be thrown
To Reproduce
Please see the code snippet below to reproduce the issue (or on RunKit).
Expected behaviour
In the above example, the expected outcome is that the request would fail again with an error code 500, however in a real-world scenario, you could wait for x amount of time before retrying the request again.
Environment
The text was updated successfully, but these errors were encountered: