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

Timeout configuration? #56

Closed
chrismcv opened this issue Apr 8, 2015 · 9 comments
Closed

Timeout configuration? #56

chrismcv opened this issue Apr 8, 2015 · 9 comments
Milestone

Comments

@chrismcv
Copy link

chrismcv commented Apr 8, 2015

hi,
I was wondering if there is a way to configure the default timeout for axios requests?

thanks,
chris

@mzabriskie
Copy link
Member

Currently no option for this. But it would be a good feature.

@mzabriskie mzabriskie added this to the 0.6.0 milestone Apr 8, 2015
@WillsB3
Copy link

WillsB3 commented Apr 17, 2015

+1 for this feature.

@chrismcv
Copy link
Author

FYI - I'm doing it like this presently as a workaround

timeout = (s, promise) ->
  new Promise (resolve, reject) ->
    promise.then(resolve);
    setTimeout((-> 
      e = new Error('Timeout after '+s+' s')
      e.statusCode = 'timeout'
      reject e
    ), s * 1000);

timeout(10, axios.get(url)).catch globalErrorHandler

mzabriskie added a commit that referenced this issue Jun 19, 2015
@mzabriskie
Copy link
Member

This will be available when 0.6.0 is released.

@WillsB3
Copy link

WillsB3 commented Jun 20, 2015

Awesome - Thanks 👍

mzabriskie added a commit that referenced this issue Aug 11, 2015
mzabriskie added a commit that referenced this issue Aug 11, 2015
@mzabriskie
Copy link
Member

I just released 0.6.0 which includes a fix for this.

@tnrich
Copy link

tnrich commented Mar 9, 2016

hey @mzabriskie, could you please provide an example of how to use the timeout config for a single request?

Thanks very much!
Thomas

@ghost
Copy link

ghost commented Apr 15, 2016

@tnrich axios.get('your-url', {'timeout': 1000});

I hope this helps.

@ghost
Copy link

ghost commented Apr 15, 2016

@mzabriskie I have set axios.defaults.timeout = 1000;

I disconnected the server that provides me with the rest API.

But it takes more that 1 ms to timeout after sending a request.

This is how my request looks:

    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;
      });

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

No branches or pull requests

4 participants