您的位置:首页 > Web前端 > React

ReactNativeiOS(三)开发零碎1 Fetch错误Network request failed

2015-12-27 17:38 597 查看
开发状态下,如果网络不通,或者 api 无效,都会给出一个大红屏幕,写着Network request failed

这个是开发状态的,实际release的产品不会,但还是要处理掉这些异常,红色屏幕对开发也是不友好的

对于ES6不熟,只好查资料,https://github.com/facebook/react-native/issues/973

jbhatab commented on
Apr 23

This is what happens when I make a failed api request. Are failed api requests supposed to break the app like this? Is there a good way to have a fallback?





jbhatab changed
the title from Network request failed to Failed API request breaks app on
Apr 23





burriko commented on
Apr 23

Can we see your code? I haven't had any problems catching errors from network problems so far.
Here's an example using fetch().

fetch('http://example.com/stuff.json')
.then(response => response.json())
.then(json => this._handleResponse(json))
.catch(error => {
React.AlertIOS.alert(
'Error',
'There seems to be an issue connecting to the network.'
);
});






joshbedo commented on
Apr 24

Adding a
catch
solved this issue for me, thanks! :)


brentvatne changed
the title from Failed API request breaks app to [fetch] Failed API request breaks appon
May 31





Collaborator

brentvatne commented on
May 31

This should only happen in development mode, if you can reproduce with development mode disabled, please ping me and I'll reopen this issue! @jbhatab
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: