apisauce: Timeout not working on android.

When app cannot connect to API, the timeout will not be working on android. But ios still run ok. timeout

my package.json

"apisauce": "^0.14.3",
"react-native": "0.54.2",
"react": "16.3.0-alpha.1",
"redux-saga": "^0.16.0"

About this issue

  • Original URL
  • State: open
  • Created 6 years ago
  • Reactions: 7
  • Comments: 25 (2 by maintainers)

Most upvoted comments

Hello everyone, for the moment, this is my solution.

import { create, TIMEOUT_ERROR } from 'apisauce';

import apiConfig from './config';

const requestTimeout = (promise, axiosConfig, reqConfig) => {
  const { timeout } = apiConfig;
  const config = { ...axiosConfig, ...(reqConfig || {}) };
  const duration = (parseInt(config.timeout, 10) || timeout) + 1000;
  const timeoutPromise = new Promise(
    (resolve => setTimeout(() => resolve({
      ok: false,
      problem: TIMEOUT_ERROR,
      originalError: 'REQUEST_TIMEOUT_ERROR',
      data: null,
      status: null,
      headers: null,
      config,
      duration
    }), duration))
  );
  return Promise.race([timeoutPromise, promise]);
};

const buildApi = (config = apiConfig) => {
  const api = create(config);
  const {
    axiosInstance: { defaults }, get, delete: del, head, post, put, patch, link, unlink
  } = api;
  api.get = (...args) => requestTimeout(get(...args), defaults, args[2]);
  api.delete = (...args) => requestTimeout(del(...args), defaults, args[2]);
  api.head = (...args) => requestTimeout(head(...args), defaults, args[2]);
  api.post = (...args) => requestTimeout(post(...args), defaults, args[2]);
  api.put = (...args) => requestTimeout(put(...args), defaults, args[2]);
  api.patch = (...args) => requestTimeout(patch(...args), defaults, args[2]);
  api.link = (...args) => requestTimeout(link(...args), defaults, args[2]);
  api.unlink = (...args) => requestTimeout(unlink(...args), defaults, args[2]);
  return api;
};

export default buildApi;

any update on this?

still facing this issue, any updates?