Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs console.error:";“未处理的错误”;网络错误:网络请求失败_Reactjs_React Native_Apollo_React Apollo_Apollo Client - Fatal编程技术网

Reactjs console.error:";“未处理的错误”;网络错误:网络请求失败

Reactjs console.error:";“未处理的错误”;网络错误:网络请求失败,reactjs,react-native,apollo,react-apollo,apollo-client,Reactjs,React Native,Apollo,React Apollo,Apollo Client,在我的react本机应用程序中,出现了这样一个错误红色屏幕 当我在设备(真实设备或模拟器)中禁用internet连接或出现任何类型的服务器错误时,就会发生此错误 我将按照下面的文档信息“处理”apollo和react native的错误: 在我的代码中有如下内容: import React, { Component } from 'react'; import { Platform, StyleSheet, Text, ActivityIndicator,

在我的react本机应用程序中,出现了这样一个错误红色屏幕

当我在设备(真实设备或模拟器)中禁用internet连接或出现任何类型的服务器错误时,就会发生此错误

我将按照下面的文档信息“处理”apollo和react native的错误:

在我的代码中有如下内容:

import React, { Component } from 'react';
import {
    Platform,
    StyleSheet,
    Text,
    ActivityIndicator,
    View,
    FlatList,
    TouchableHighlight,
    TextInput,
    Button,
} from 'react-native';
import PropTypes from 'prop-types';
import { graphql, compose } from 'react-apollo';
import ZONES_QUERY from '../graphql/zones.query'


class ZonesScreen extends Component {


    render() {
        const { zones, loading, error } = this.props;


        if (loading) {
            return (
                <ActivityIndicator style={styles.activityIndicator} size='large' />
            )
        } else if (error) {
            return (
                <View style={styles.container}>
                    <Text>Unexcpeted Error</Text>
                    <Button title="retry" onPress={() => { this.props.refetch() }}></Button>

                </View>

            )
        } else {
            return (
                <View
                    style={styles.container}>
                    <FlatList
                        data={zones}
                        renderItem={({ item }) => ZoneRenderItem(item)}
                        keyExtractor={this.keyExtractor}

                    />
                </View>
            )
        }
    }

    //HELPER FUNCTIONS

    keyExtractor = item => item._id;
}

ZonesScreen.propTypes = {
    refetch: PropTypes.func,
}


const zonesQuery = graphql(ZONES_QUERY, {
    options: {
        forceFetch: true,
        fetchPolicy: 'network-only',
        notifyOnNetworkStatusChange: true,
    },
    props: ({ data: { loading, getRoutes, error, refetch } }) => ({
        loading,
        zones: getRoutes,
        refetch,
        error,
    }),
})



const styles = StyleSheet.create({
    container: {
        flex: 1,
        justifyContent: 'center',
        backgroundColor: '#eee',
    },
    activityIndicator: {
        flex: 1,
        justifyContent: 'center',
    },
});

export default compose(
    zonesQuery,
)(ZonesScreen)
const errorLink = onError(({ graphQLErrors, networkError}) => {
    console.log("ERROR: " +networkError)    
})

const client = new ApolloClient({
    link: concat(errorLink, httpLink),
    cache: new InMemoryCache(),
});
我有两个屏幕

屏幕A:它确实包含转到屏幕B的按钮。 屏幕B:包含区域列表(此信息从服务器获取)

下面是重现此错误的步骤:

    • 我打开应用程序。(我看到屏幕A)。我从设备上禁用internet连接,我点击按钮进入屏幕B
  • 屏幕B显示一条错误消息。这在我的代码行中处理:

    else如果(错误){}

  • 这是预期的行为,但当我通过按导航栏/工具栏中的后退按钮返回屏幕A时。显示红色屏幕

    我不知道我错过了什么

    任何帮助都是好的,提前谢谢

    我正在使用

    “react本机路由器流量”:“4.0.0-beta.27”

    “反应阿波罗”:“2.0.4”