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

Retry of the original request fails only if GET request #214

Open
GiovanniSlabs opened this issue Oct 12, 2022 · 4 comments
Open

Retry of the original request fails only if GET request #214

GiovanniSlabs opened this issue Oct 12, 2022 · 4 comments

Comments

@GiovanniSlabs
Copy link

Hi,
this is my configuration

const sendRequest = axios.create({
    baseURL: import.meta.env.VITE_SERVER_URL,
    withCredentials: true
})

const refreshAuthLogic = (failedRequest) => sendRequest.post('/admin/refresh').then(() => {
    setUserInfo(prev => ({
        ...prev,
        logged: true,
    }))
    return Promise.resolve()
}).catch(error => {
    //se non va a buon fine butto fuori l'utente
    setUserInfo({
        logged: false,
        info: {}
    })

    return Promise.reject(error);
});

// Instantiate the interceptor
createAuthRefreshInterceptor(sendRequest, refreshAuthLogic);

my tokens are all saved in cookies.

The problem is that if the original request is a POST request it works.
But if the original request is a GET the retry request after the refresh request fails with this error:

DOMException: Failed to execute 'setRequestHeader' on 'XMLHttpRequest': 'function(header, parser) {
header = normalizeHeader(header);
if (!header)
  return void 0;
const key = findKey(this, header);
if (key) {
  const value = this[key];
  if (!parser) {
    return value;
  }
  if (parser === true) {
    return parseTokens(value);
  }
  if (utils_default.isFunction(parser)) {
    return parser.call(this, value, key);
  }
  if (utils_default.isRegExp(parser)) {
    return parser.exec(value);
  }
  throw new TypeError("parser must be boolean|regexp|function");
}
}' is not a valid HTTP header field value.

I don't know if i miss something or there is a bug.

thank you.

@olksndrdevhub
Copy link

@GiovanniSlabs am stuck with the same error and still looking for solutions. Did you find out? let me know, please)

@GiovanniSlabs
Copy link
Author

Hi @olksndrdevhub,
yes after many test i find out that this problem is due to a bug in the new version of axios > 1.0.0

The error is when axios try to set the header in retring the failed request

axios(request_options).then(() => {
    ...
}).catch(error => {
    const originalRequest = error.config;

    return axios(originalRequest) // here it messes up in setting the header correctly
});

So using v0.27.2 of axios solve the problem.

@Flyrell
Copy link
Owner

Flyrell commented Oct 17, 2022

Thanks for catching that @GiovanniSlabs

@Jumail
Copy link

Jumail commented Nov 7, 2022

Any solutions to fix this instead of downgrading axios version?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants