Skip to content
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

Undefined 'code' TypeError within errorNormalize #7850

Closed
rvajustin opened this issue Mar 12, 2024 · 2 comments
Closed

Undefined 'code' TypeError within errorNormalize #7850

rvajustin opened this issue Mar 12, 2024 · 2 comments

Comments

@rvajustin
Copy link

rvajustin commented Mar 12, 2024

When running Apollo Server 4.10.1, I am running into an unhandled TypeError where extensions is undefined, so the error code cannot be retrieved from the object.

Here is the diff that solved my problem:

diff --git a/node_modules/@apollo/server/src/errorNormalize.ts b/node_modules/@apollo/server/src/errorNormalize.ts
index 55efdde..ecdb82d 100644
--- a/node_modules/@apollo/server/src/errorNormalize.ts
+++ b/node_modules/@apollo/server/src/errorNormalize.ts
@@ -60,11 +60,13 @@ export function normalizeAndFormatErrors(
 
     const extensions: GraphQLErrorExtensions = {
       ...graphqlError.extensions,
-      code:
-        graphqlError.extensions.code ??
-        ApolloServerErrorCode.INTERNAL_SERVER_ERROR,
+      code: ApolloServerErrorCode.INTERNAL_SERVER_ERROR,
     };
 
+    if (graphqlError && graphqlError.extensions && graphqlError.extensions.code) {
+      extensions.code = graphqlError.extensions.code;
+    }
+
     if (isPartialHTTPGraphQLHead(extensions.http)) {
       mergeHTTPGraphQLHead(httpFromErrors, {
         headers: new HeaderMap(),
@glasser
Copy link
Member

glasser commented Mar 15, 2024

As discussed at #7851 (comment) this issue only arises if you combine AS4 with a version of graphql-js that it explicitly does not support.

@glasser glasser closed this as completed Mar 15, 2024
Copy link
Contributor

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
For general questions, we recommend using StackOverflow or our discord server.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants