2017-07-21 31 views
-1

I got this error in my application (react-native) when internet connection is lost. When i start the app on offline mode, Initial component renders, try to execute the query, app crashes. it works perfect when my app is connected with internet. But my application crashes when its not. How can i handle this error?未処理エラーネットワークエラー:ネットワーク要求がエラーを失敗しました:ネットワーク要求がエラーを失敗しました:71「未処理エラーネットワークエラー:ネットワーク要求がエラーを失敗しました:ネットワークエラー:ネットワーク要求が新しいで失敗した新しいApolloError

ExceptionsManager.jsでApolloError」

import ApolloClient, { createNetworkInterface } from 'apollo-client'; 
import { AsyncStorage } from 'react-native'; 
import {SubscriptionClient, addGraphQLSubscriptions} from 'subscriptions-transport-ws'; 

const wsClient = new SubscriptionClient('wss://172.20.32.6:5000', { 
    reconnect: true, 
    connectionParams: { 
    accessToken: 'jka sdhkjashd jkashdjk ashdas' 
    } 
}); 

const networkInterface = createNetworkInterface({ 
    uri: 'http://172.20.32.6:8000/graphql', 
    opts: { 
    credentials: 'same-origin' 
    } 
}); 
const networkInterfaceWithSubscriptions = addGraphQLSubscriptions(
    networkInterface, 
    wsClient 
); 
const client = new ApolloClient({ 
    dataIdFromObject: o => o.id, 
    networkInterface: networkInterfaceWithSubscriptions 

}); 
networkInterface.use([{ 
    applyMiddleware(req, next) { 
    if (!req.options.headers) { 
     req.options.headers = {}; // Create the header object if needed. 
    } 
    // get the authentication token from local storage if it exists 
    AsyncStorage.getItem('sessionToken').then((token) => { 
     req.options.headers.Authorization = token ? `${token}` : null; 
     next(); 
    } 
    ); 
    } 
}]); 
export default client; 

enter image description here

答えて

0

部品の上部に、このようなものを追加し、この非常に助けにならないエラーを回避するにはクエリ結果がレンダリングされます。エラーの対処

if (data && data.error) { 
    return (
     <View> 
     <Text>{JSON.stringify(data.error)}</Text> 
     </View> 
    ) 
} 

詳細はこのgithubの問題で見つけることができ https://github.com/apollographql/react-apollo/issues/604

関連する問題