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

If "withCredentials: true", then a 4xx response produces an error of type ERR_NETWORK, not allowing to access the response object #6386

Open
matricali opened this issue May 9, 2024 · 0 comments

Comments

@matricali
Copy link

Describe the bug

I figured out that when I'm using "withCredentials: true" I've got a NETWORK_ERROR for a 401 or 403 response, instead of ERR_BAD_REQUEST.
But without "withCredentials: true" I've got an error of type ERR_BAD_REQUEST as expected.

To Reproduce

import axios from "axios";

// Create an Axios instance with default options
const axiosInstance = axios.create({
baseURL: 'http://an.endpoint.com/api/v1',
withCredentials: true,
});

axiosInstance.interceptors.response.use(
response => response,
error => {
console.log('Axios response error', error); // <-----------
if (error.response.status === 401) {
// handle invalid token
console.log('Invalid token - requesting new access token');
// request new access token and retry request
// note: you can access the original request config with error.config
}
return Promise.reject(error);
}
);

export default axiosInstance;

Code snippet

No response

Expected behavior

It should return an error of type ERR_BAD_REQUEST, allowing to access response object

Axios Version

1.6.8

Adapter Version

No response

Browser

Chrome

Browser Version

124.0.6367.119

Node.js Version

No response

OS

No response

Additional Library Versions

React 18.3.1

Additional context/Screenshots

No response

@matricali matricali changed the title If "withCredentials: true" the error produced always If "withCredentials: true", then a 4xx response produces an error of type ERR_NETWORK May 9, 2024
@matricali matricali changed the title If "withCredentials: true", then a 4xx response produces an error of type ERR_NETWORK If "withCredentials: true", then a 4xx response produces an error of type ERR_NETWORK, not allowing to access the response object May 9, 2024
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

1 participant