react-admin: [ra-data-graphql-simple] Http 401 error is not redirecting to login page

What you were expecting:

I expected to be redirected to the login page when the graphql endpoint returns http 401 or 403

What happened instead:

It displays the error message, but continues and tries to parse the null data returned

Steps to reproduce:

  • Have the graphql endpoint return 401 for a query, with an error message and null data

Related code:

Other information:

Environment

  • React-admin version: “^2.7.3” “ra-data-graphql-simple”: “^2.7.1”,
  • React version: “^16.8.4”
  • Browser: Google Chrome
  • Stack trace (in case of a JS error): Below is what gets printed to console.log
index.js:83 POST http://localhost:3001/graphql 401 (Unauthorized)
index.js:1446 Warning: Missing translation for key: "GraphQL error: LOGIN_USER
GraphQL error: LOGIN_USER
GraphQL error: Non-nullable field was null."
index.js:1446 Warning: Missing translation for key: "GraphQL error: LOGIN_USER
GraphQL error: LOGIN_USER
GraphQL error: Non-nullable field was null."

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 19 (8 by maintainers)

Commits related to this issue

Most upvoted comments

See #3604 (comment)

I see that however, I have a null check in render() checking this.state.dataProvider which doesn’t get set if Apollo returns an error. My workaround was to return a function that throws an error with the status code since react-admin expects a function for dataProvider.

    const httpLink = createHttpLink(options);
    const errorLink = onError(({ networkError }) => {
      if (networkError.statusCode < 200 || networkError.statusCode >= 300) {
        networkError.status = networkError.statusCode;
        this.setState({
          dataProvider: function() {
            throw networkError;
          },
        });
      }
    });

If I remove the null check the app fails since dataProvider is null.