我正在使用fetch在react-native中进行一些API调用,有时随机fetch不会向服务器发送请求,而我的then或except块也不会被调用.这是随机发生的,我认为可能存在竞争条件或类似情况.在这样的请求失败后,对同一API的请求永远不会被解雇,直到我重新加载应用程序.任何想法如何追踪这背后的原因.我使用的代码如下.
const host = liveBaseHost;
const url = `${host}${route}?observer_id=${user._id}`;
let options = Object.assign({
method: verb
}, params
? {
body: JSON.stringify(params)
}
: null);
options.headers = NimbusApi.headers(user)
return fetch(url, options).then(resp => {
let json = resp.json();
if (resp.ok) {
return json
}
return json.then(err => {
throw err
});
}).then(json => json);
Run Code Online (Sandbox Code Playgroud)