Skip to content

Error code from GraphQL is not correct in StrawberryShake #4596

Closed

Description

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

I expected my StrawberryShake client to return error codes from the GraphQL response, but result.Errors[0].Code is null. The error code can be found inside result.Errors[0].Extensions["body"], but I assume that this is not how this is intended to work? Perhaps some sort of serialization bug?

I made a quick reproduction here: https://github.com/thomastvedt/HotChocolateBug

The following mutation:

mutation {
  saveUserEmail(userId:"123", email:"incalid_email") {
    id
    name
    age
    email
  }
}

results in the following GraphQL response:

{
  "errors": [
    {
      "message": "Invalid email",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "saveUserEmail"
      ],
      "extensions": {
        "message": "Invalid email",
        "stackTrace": "   at Server.Domain.UserService.SaveUserEmail(String id, String email) in /Users/thomastvedt/projects/HotChocolateBug/Server/Domain/UserService.cs:line 13\n   at Server.UserMutation.SaveUserEmail(String userId, String email, UserService userService) in /Users/thomastvedt/projects/HotChocolateBug/Server/UserMutation.cs:line 10\n   at HotChocolate.Resolvers.Expressions.ExpressionHelper.AwaitTaskHelper[T](Task`1 task)\n   at HotChocolate.Types.Helpers.FieldMiddlewareCompiler.<>c__DisplayClass9_0.<<CreateResolverMiddleware>b__0>d.MoveNext()\n--- End of stack trace from previous location ---\n   at HotChocolate.Execution.Processing.Tasks.ResolverTask.ExecuteResolverPipelineAsync(CancellationToken cancellationToken)\n   at HotChocolate.Execution.Processing.Tasks.ResolverTask.TryExecuteAsync(CancellationToken cancellationToken)",
        "code": "CUSTOM_ERROR_CODE"
      }
    }
  ]
}

When running the console app with the generated StrawberryShake client I get the following result:

image

I was expecting to find my CUSTOM_ERROR_CODE under result.Errors[0].Code, but this is null.

Is this a bug or expected?

Steps to reproduce

I made a quick reproduction here: https://github.com/thomastvedt/HotChocolateBug

  1. Run server (HotChocolate server)
  2. Run console app (StrawberryShake client)

Relevant log output

No response

Additional Context?

No response

Product

Strawberry Shake

Version

12.4.1

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

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions