apisauce
apisauce copied to clipboard
Timeout not working on android.
When app cannot connect to API, the timeout will not be working on android. But ios still run ok.
my package.json
"apisauce": "^0.14.3",
"react-native": "0.54.2",
"react": "16.3.0-alpha.1",
"redux-saga": "^0.16.0"
Hmm. What android version are we talking here?
@skellock I tried with emulator 5.1, 6.1 and 7.
+1 -- I'm having the same problem.
same here , testing on emulator
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;
Can this be related to https://github.com/facebook/react-native/issues/11666 ?
still facing this issue, any updates?
I am also facing this issue.
I am also facing this issue, too.
I am also facing this issue, too [2].
same here
same here
same here
any update on this?
Same here in android emulator. I've deactivated wifi and LTE from the emulator and .get call never finishes, even if i've configured a timeout.
[email protected]
[email protected]
Still persist in the latest version.
@SafdarSikander @sdandois @Sajid-Ali is this still an issue ?
any update on this issue?
Might be related to https://github.com/axios/axios/issues/2073
I have used the promise
with race conditions
to solve this problem
the comment from here where @rcstanciu pointed seems to work with the apisauce as well.
basically call a cancelation with a setTimeout()
instead of using the built in timeout of apisauce
let axiosCall;
if (Platform.OS === "android") {
axiosCall = axios.CancelToken.source();
setTimeout(() => {
axiosCall.cancel("Timeout of 30000ms exceeded");
}, 30000);
}
return yourApisauceCreate
.post("test", payload, {
...(axiosCall && {
cancelToken: axiosCall.token
})
})
the comment from here where @rcstanciu pointed seems to work with the apisauce as well.
basically call a cancelation with a
setTimeout()
instead of using the built in timeout of apisaucelet axiosCall; if (Platform.OS === "android") { axiosCall = axios.CancelToken.source(); setTimeout(() => { axiosCall.cancel("Timeout of 30000ms exceeded"); }, 30000); } return yourApisauceCreate .post("test", payload, { ...(axiosCall && { cancelToken: axiosCall.token }) })
is it working for you .??
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;
it work for me! tks a lot 💯 💯 💯
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;
Keep in mind that timed out response will skip api monitor if you have it set up.
do we the official resolution for this issue? cause i have used the latest version. But still got only 10 secs API timeout while im already set the timeout.
I notice that, it only happens on the released app, on development mode its working fine.
My config: