graphql-engine: actions: ability to send `extensions` to error responses

I use the latest “hasura/graphql-engine:v1.2.0-beta.1”, after testing actions I found that it responds in different formats for 5xx and 4xx errors. For 5xx errors I could get from the response any custom objects with data from the server

{
  "errors": [
    {
      "extensions": {
        "internal": {
          "webhook_response": {
            "errors": [
              {
                "status": 500,
                "code": "Error",
                "detail": "hello world"
              }
            ]
          }
        },
        "path": "$",
        "code": "unexpected"
      },
      "message": "internal error"
    }
  ]
}

When for 4xx it only accepts {"message": "error message"} any custom options will not be displayed at “extensions” - “internal” like for 5xx error.

I would like to have 4xx support any custom formats with the ability to path more information rather than just a “message” field.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 4
  • Comments: 21 (8 by maintainers)

Most upvoted comments

It seems that the issue is only for the RESTified graphql endpoints. When I run the mutation from the action, it returns the extensions. However, the REST endpoint that uses that mutation does not return it.

The git commit which introduced this change (mentioned in https://github.com/hasura/graphql-engine/issues/4001#issuecomment-922710659) has the tags v2.1.0-beta.1 and above. Pls try this with the latest release: v2.1.0-beta.2

I’m facing the same problem with v2.0.9. Based on the documentation I would expect that this Action Handler response:

res.status(422).send({
  message: "Config Validation Error",
  extensions: {
    code: "validation-failed",
    foo: "bar",
  },
});

would return this form the GraphQL API:

{
  "errors": [
    {
      "extensions": {
        "code": "validation-failed",
        "foo": "bar"
      },
      "message": "Config Validation Error"
    }
  ]
}

But this is what I currenlty get back:

{
  "errors": [
    {
      "extensions": {
        "path": "$",
        "code": "unexpected"
      },
      "message": "Config Validation Error"
    }
  ]
}

Am I missing something? Is this not the exptected behaviour? @tirumaraiselvan

Looks like this is still broken.

{
    message: 'ActionError: EMAIL_NOT_ALLOWED',
    extensions: { foo: 'bar', code: 'EMAIL_NOT_ALLOWED' }
}

gives:

{
    "path": "$",
    "error": "ActionError: EMAIL_NOT_ALLOWED",
    "code": "unexpected"
}

I’ve just attempted to replicate this behavior with no success. This is my action handler’s code:

    res.status(400).json({
      message: 'ActionError: EMAIL_NOT_ALLOWED',
      extensions: { foo: 'bar', code: 'EMAIL_NOT_ALLOWED' },
    });

And this is the payload from calling my action through hasura:

{
  "errors": [
    {
      "extensions": {
        "foo": "bar",
        "code": "EMAIL_NOT_ALLOWED"
      },
      "message": "ActionError: EMAIL_NOT_ALLOWED"
    }
  ]
}

This is the behavior we are expecing. Can you share more details on your setup, and if possible minimal reproduction steps? We tested this on 2.1.1.