【发布时间】:2020-10-13 09:44:19
【问题描述】:
我的应用在执行某些 API 调用时严重崩溃,我将其范围缩小到这一点:
- 这不是 HTTP 与 HTTPS 的事情
- 我最终使用了两种不同的模拟 API,令我惊讶的是,一种有效,另一种无效。两者基本相同,见下sn-p
- 在 WIFI 或蜂窝网络上的行为相同
- 在 axios 而不是 fetch 中存在同样的问题
-
catch块被调用时出现无法描述的网络错误,但随后应用仍然严重崩溃
环境:Android 10(实际设备),RN 0.61.5
下面的两个调用都只是执行一个简单的HTTP GET,这会导致返回一个 JSON sn-p。一个有效,另一个导致严重崩溃。
async foo() {
try {
// this endpoint CRASHES my app
const r = await fetch("http://jsonplaceholder.typicode.com/todos/1");
// this endpoint works just fine
//const r = await fetch("http://echo.jsontest.com/key/value/one/two");
} catch(e) {
console.log("Invoked, but the app still crashes hard right after");
}
}
【问题讨论】:
-
请告知问题的解决方案。
-
我发布了我的修复作为答案@TanviAgarwal -
标签: axios fetch react-native-android