q3e / react-native-github-graphql-app

React Native App that searches github projects and their contributors[WIP]
MIT License
2 stars 0 forks source link

Handle network errors from apollo-client console.error: #2

Closed q3e closed 6 years ago

q3e commented 6 years ago

image

Error results from

Unhandled error Network error: Network request failed with status 401 - "undefined" Error: Network error: Network request failed with status 401 - "undefined"

related to permisions related issue

q3e commented 6 years ago

https://github.com/apollographql/apollo-client/blob/master/Upgrade.md#upgrading-from-custom-networkinteface-with-middleware--afterware

this error handling didnt get rid of the error

const httpLink = createHttpLink({ uri: '/graphql' });
const errorLink = onError(({ networkError }) => {
  if (networkError.statusCode === 401) {
    logout();
  }
})
q3e commented 6 years ago

This Question on SO

[edit] Solved on SO. see the above link just change authorization: 'GITHUB_ACCESS_TOKEN'

to authorization : `Bearer ${GITHUB_ACCESS_TOKEN} helped me get rid of the error.

ofcourse that variable refering to the token I generated.

Plus I missed the 'Bearer' keyword.