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

来源:互联网 发布:嵌入式编程入门 编辑:程序博客网 时间:2024/05/22 17:26

开发状态下,如果网络不通,或者 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?

screen shot 2015-04-22 at 4 05 37 pm

@jbhatabjbhatab changed the title from  Network request failed to Failed API request breaks app on Apr 23
@burriko
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
joshbedo commented on Apr 24

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

@brentvatnebrentvatne changed the title from  Failed API request breaks app to [fetch] Failed API request breaks appon May 31
@brentvatne
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


0 0
原创粉丝点击