Raman Choudhary
Raman Choudhary

Reputation: 4393

API Timeout on React Native Pepperoni Starter Kit

I'm using React Native Pepperoni Starter Kit. I using one the function post to fetch data from the server. Whenever I make the call, API fails because of timeout but server receives the call. The only client shows it has failed.

onboardingState.js

   export function validatePhone(phoneNumber){
  return dispatch => {
    post('/api/users/register',{
      number : phoneNumber,
      deviceInfo : {}
    },false).then((res)=>{
      console.log('POST SUCCESS');
      console.log(res);
    }).catch((error)=>{
      console.log('POST ERROR');
      console.log(error);
    });
  }
}

File I'm using to make the call. api.js

Upvotes: 1

Views: 162

Answers (1)

Facundo La Rocca
Facundo La Rocca

Reputation: 3866

I think you are missing the reject callback.

Try this:

export function validatePhone(phoneNumber){
  return dispatch => {
    post('/api/users/register',{
      number : phoneNumber,
      deviceInfo : {}
    }, false)
    .then((res)=>{
      console.log('POST SUCCESS');
      console.log(res);
    }, (cause) => {
      console.log('POST REJECTED');
      console.log(cause);
    })
    .catch((error)=>{
      console.log('POST ERROR');
      console.log(error);
    });
  }
}

Let me know if it works. There isn't too much information, but It seems lack of reject callback is causing the failure. I mean, lack of reject callback is preventing you to realize the original error you are receiving.

You must to ensure that the server is responding correctly. An scenario could be your server receiving the request but not sending the response to the client. Did you check it?

There is default timeout into Api.js of 6 seconds and it seems not to be able to be modified. Check 8th line in Api.js, you will see this:

const TIMEOUT = 6000;

Consider using another lib in order to fetch your info from the server like fetch or modify by your own Api.js to set that TIMEOUT larger.

Upvotes: 1

Related Questions