I set axios.defaults.timeout = 1000;
I stopped the server that provides me the API.
But after sending the request, the wait time exceeds 1 s.
This is what my query looks like:
import axios from 'axios'; axios.defaults.timeout = 1000; return axios.post('${ROOT_URL}/login/${role}', creds).then((response) => { console.log(response); if(response.status === 200) { // If login was successful, set the token in local storage localStorage.setItem('${role}_log_toks', JSON.stringify(response.data)); // Dispatch the success action dispatch(receiveLogin(response.data)); return response; } }).catch(err => { console.log(err); // If there was a problem, we want to // dispatch the error condition if(err.data && err.status === 404) { dispatch(loginError(err.data)); } else { dispatch(loginError('Please check your network connection and try again.')); } return err; });
I also tried:
return axios.post('${ROOT_URL}/login/${role}', creds, {timeout: 1000}).then...
Axios does not stop sampling and after 5-10 minutes finally shows a network error. I understand that there are other timeout processing methods, but why does the timeout function in axios not work? What could be the reason that Axios does not stop receiving?
Axios version 0.9.1
EDIT: As mentioned in the comments, I also tried:
import axios from 'axios'; const httpClient = axios.create(); httpClient.defaults.timeout = 500; return httpClient.post('${ROOT_URL}/login/${role}', creds) .then(handleResponse)
source share