Apollo-server: Response not successful: Received status code 500

Created on 23 Jul 2018  Â·  3Comments  Â·  Source: apollographql/apollo-server

I am trying to migrate to version 2. I am using the following code to send user information inside jwt token to the context.

const server = new ApolloServer({
    typeDefs: gql`${typeDefs}`,
    resolvers,
    context: ({ req, res }) => {
        const username = validateJWT(req.headers)
        return { username }
    }
})

validateJWT is a function which throws error if jwt is invalid. If the jwt is empty, it returns null and if jwt is valid it returns a username.

This is working fine when jwt is empty or valid. But when jwt is invalid, it throws an error which is visible momentarily in playground and then the playground switches to:

{
  "error": "Response not successful: Received status code 500"
}

Looks like response is not triggered?

Most helpful comment

I hit this issue when run apollo service:push command

> apollo service:push

  ✔ Loading Apollo Project
  ✖ Uploading service to Engine
    → Response not successful: Received status code 500
ServerError: Response not successful: Received status code 500
    at Object.exports.throwServerError (~/workspace/github.com/mrdulin/apollo-graphql-tutorial/node_modules/apollo-link-http-common/lib/index.js:23:17)
    at ~/workspace/github.com/mrdulin/apollo-graphql-tutorial/node_modules/apollo-link-http-common/lib/index.js:48:21
    at <anonymous>

update

I figure it out. Because I add auth feature to ContextFunction, if there is no authorization request headers in apollo.config.js. The error will throw

  const token: string = validateToken(req);
    const userConnector = new UserConnector<IMemoryDB>(memoryDB);
    let user: IUser | undefined;
    try {
      const userType: UserType = UserType[token];
      user = userConnector.findUserByUserType(userType);
    } catch (error) {
      throw error;
    }

apollo.config.js:

module.exports = {
  service: {
    endpoint: {
      url: 'http://localhost:3000/',
      headers: {
        authorization: 'Bearer ZOWI'
      }
    }
  }
};

All 3 comments

Do you get the whole error when making the call though curl or another HTTP client? I believe the disappearing error is a Playground issue, so you should probably open an issue there.

Closing due to a lack of response. I agree the disappearing error is a (frustrating) GraphQL Playground issue, but thank you for opening that issue on the other repository.

Happy to re-open this if you can provide a reproduction of the problem with the actual error — via curl as suggested (you can generate and copy/paste the command from GraphQL Playground into a terminal). Thanks!

I hit this issue when run apollo service:push command

> apollo service:push

  ✔ Loading Apollo Project
  ✖ Uploading service to Engine
    → Response not successful: Received status code 500
ServerError: Response not successful: Received status code 500
    at Object.exports.throwServerError (~/workspace/github.com/mrdulin/apollo-graphql-tutorial/node_modules/apollo-link-http-common/lib/index.js:23:17)
    at ~/workspace/github.com/mrdulin/apollo-graphql-tutorial/node_modules/apollo-link-http-common/lib/index.js:48:21
    at <anonymous>

update

I figure it out. Because I add auth feature to ContextFunction, if there is no authorization request headers in apollo.config.js. The error will throw

  const token: string = validateToken(req);
    const userConnector = new UserConnector<IMemoryDB>(memoryDB);
    let user: IUser | undefined;
    try {
      const userType: UserType = UserType[token];
      user = userConnector.findUserByUserType(userType);
    } catch (error) {
      throw error;
    }

apollo.config.js:

module.exports = {
  service: {
    endpoint: {
      url: 'http://localhost:3000/',
      headers: {
        authorization: 'Bearer ZOWI'
      }
    }
  }
};
Was this page helpful?
0 / 5 - 0 ratings