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

Comments

Projects
None yet
4 participants
@chrismcv
Copy link

commented Apr 8, 2015

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

thanks,
chris

@mzabriskie

This comment has been minimized.

Copy link
Member

commented Apr 8, 2015

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

@mzabriskie mzabriskie added the feature label Apr 8, 2015

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

@WillsB3

This comment has been minimized.

Copy link

commented Apr 17, 2015

+1 for this feature.

@chrismcv

This comment has been minimized.

Copy link
Author

commented Apr 30, 2015

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

This comment has been minimized.

Copy link
Member

commented Jun 19, 2015

This will be available when 0.6.0 is released.

@mzabriskie mzabriskie closed this Jun 19, 2015

@WillsB3

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link
Member

commented Sep 21, 2015

I just released 0.6.0 which includes a fix for this.

@tnrich

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link

commented Apr 15, 2016

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

I hope this helps.

@ghost

This comment has been minimized.

Copy link

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 join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.