New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apollo Server returns INTERNAL_SERVER_ERROR as code after throwing AuthenticationError #1100

Closed
harisvsulaiman opened this Issue May 27, 2018 · 11 comments

Comments

Projects
None yet
6 participants
@harisvsulaiman

harisvsulaiman commented May 27, 2018

Apollo Server @2.0beta returns INTERNAL_SERVER_ERROR as code after throwing AuthenticationError.
As per the docs it should have thrown UNAuthenticated as code in extentions

code
throw AuthenticationError("Please Signin");

package.json

"dependencies": {
    "apollo-engine": "^1.1.1",
    "apollo-link-context": "^1.0.8",
    "apollo-link-http": "^1.5.4",
    "apollo-server": "^2.0.0-beta.2",
    "apollo-server-express": "^2.0.0-beta.1",
    "body-parser": "^1.18.2",
    "express": "^4.16.3",
    "firebase-admin": "~5.12.0",
    "graphql": "^0.13.2",
    "graphql-import": "^0.5.2",
    "graphql-tools": "^3.0.0",
    "node-fetch": "^2.1.2"
  },

error

{
  "data": null,
  "errors": [
    {
      "message": "Please Signin",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "user"
      ],
      "extensions": {
        "code": "INTERNAL_SERVER_ERROR",
        "exception": {
          "errors": [
            {
              "message": "Please Signin",
              "locations": [],
              "path": [
                "user"
              ]
            }
          ]
        }
      }
    }
  ]
}
@evans

This comment has been minimized.

Member

evans commented May 30, 2018

@harisvsulaiman Thanks for opening the issue!

Where are you throwing the AuthenticationError? Does it happen in resolvers or are you throwing it in the context function?

If you have a chance to create a test, in the style of this example, I would love to help solve the issue!

@harisvsulaiman

This comment has been minimized.

harisvsulaiman commented May 30, 2018

@evans

This comment has been minimized.

Member

evans commented May 30, 2018

Ah okay, are you running with NODE_ENV set to production? I've got a hunch that the error is getting masked in that case.

The other option could be that when the error is propagated up because the non-nullability it changes how the error is handled. Can you post the section of your schema and what your resolvers look like?

@evans

This comment has been minimized.

Member

evans commented May 31, 2018

@harisvsulaiman If you have a stacktrace for the error, that would be extremely helpful as well!

@evans

This comment has been minimized.

Member

evans commented Jun 13, 2018

Solved with #1113

@evans evans closed this Jun 13, 2018

@danferreira

This comment has been minimized.

Contributor

danferreira commented Jun 18, 2018

Hey @evans. I'm still getting the same generic error. Should I open a new issue?
This:

Query: {
            contacts: (root, args, { models }) => {
            throw new AuthenticationError('must authenticate');
        },
    },

results in:

{
  "data": {
    "contacts": null
  },
  "errors": [
    {
      "message": "must authenticate",
      "locations": [],
      "path": [
        "contacts"
      ],
      "extensions": {
        "code": "INTERNAL_SERVER_ERROR",
        "exception": {
          "errors": [
            {
              "message": "must authenticate",
              "locations": [],
              "path": [
                "contacts"
              ]
            }
          ],
          "stacktrace": [
            "Error: must authenticate",
            "    at new CombinedError (/app/node_modules/graphql-tools/src/stitching/errors.ts:85:5)",
            "    at Object.checkResultAndHandleErrors (/app/node_modules/graphql-tools/src/stitching/errors.ts:107:11)",
            "    at CheckResultAndHandleErrors.transformResult (/app/node_modules/graphql-tools/src/transforms/CheckResultAndHandleErrors.ts:15:12)",
            "    at /app/node_modules/graphql-tools/src/transforms/transforms.ts:37:45",
            "    at Array.reduce (<anonymous>)",
            "    at applyResultTransforms (/app/node_modules/graphql-tools/src/transforms/transforms.ts:35:21)",
            "    at /app/node_modules/graphql-tools/src/stitching/delegateToSchema.ts:81:12",
            "    at step (/app/node_modules/graphql-tools/dist/stitching/delegateToSchema.js:32:23)",
            "    at Object.next (/app/node_modules/graphql-tools/dist/stitching/delegateToSchema.js:13:53)",
            "    at fulfilled (/app/node_modules/graphql-tools/dist/stitching/delegateToSchema.js:4:58)",
            "    at <anonymous>",
            "    at process._tickCallback (internal/process/next_tick.js:182:7)"
          ]
        }
      }
    }
  ]
}

I'm using:

"apollo-server": "^2.0.0-rc.0",
"apollo-server-express": "^2.0.0-rc.0",

EDIT: nevermind, I was using the old docs as reference. Now I see what was my error

@harisvsulaiman

This comment has been minimized.

harisvsulaiman commented Jun 18, 2018

@evans I apologize for the delay!
BTW i implemented generic Apollo Error so that i could continue development.I'm sticking to the strategy for now.

@chentsulin

This comment has been minimized.

Contributor

chentsulin commented Jul 17, 2018

It seems that there are some issues between schema stitching and apollo errors:

@todkap

This comment has been minimized.

todkap commented Oct 18, 2018

Sorry for cross-linking but found this github issue after I posted my comment. I think we are seeing this issue as well (apollographql/graphql-tools#480 (comment)) when we throw a ApolloError or AuthenticationError from our resolver.

@richardscarrott

This comment has been minimized.

richardscarrott commented Nov 6, 2018

@todkap I'm also having the same problem using apollo-server-express v2.1.0 -- did you find a solution?

@todkap

This comment has been minimized.

todkap commented Nov 7, 2018

Our issue was on the graphql-tools version, rolled back from 4.0.1 to 3.1.1

Rest package are:
  graphql: ^0.13.2
  apollo-server: ^2.1.0
  graphql-tools: ^3.1.1

Also need to apply formatError word-around that suggested by other posts in order to get this to work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment