Skip to content

Unhandled error Network error: Network request failed Error: #15121

Closed
@haris-ramzan

Description

@haris-ramzan

I got this error in my application ( react-native ) when internet connection is lost.

Version

"apollo-client" "1.0.4",
"react-apollo": "1.1.1",
"react-native": "0.44.0",

Found this error on console

"ExceptionsManager.js:71 Unhandled error Network error: Network request failed Error: Network error: Network request failed at new ApolloError"

How can i fix this issue: Here is my Screen-Shot,
screenshot_1499843569

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; 


Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions