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

Add a `path` field to `FormattedError`? #259

Open
sanae10001 opened this Issue Nov 22, 2017 · 2 comments

Comments

Projects
None yet
3 participants
@nsf

This comment has been minimized.

Copy link

nsf commented Apr 13, 2018

In case if somebody decides to implement that, don't just add a path, but also it'd be nice to be able to do custom formatting on errors. Error should be an interface. For example see this article:

https://medium.com/@tarkus/validation-and-user-errors-in-graphql-mutations-39ca79cd00bf

GraphQL express middleware in js land has this hook "formatError", which allows you to return whatever you want as an error. The nice property of GraphQL errors themselves is that they can infer path info for you, but other than that it's very limited in a sense that there is only a message. Some people want custom error codes, etc. So it should be something like:

type CustomError interface {
   SetLocation(...)
   SetPath(...)
   ToJSON() []byte
   error
}

When a resolver returns an error, graphql lib should be able to set path/location for you, however what that error contains and how it produces JSON version of itself at the end is up to a lib user.

@ccbrown

This comment has been minimized.

Copy link
Contributor

ccbrown commented Jul 20, 2018

This is done in #363. And in regards to @nsf's comment, errors are now customizable to the extent that the spec allows: If your resolvers return an error that implements gqlerrors.ExtendedError, you can include arbitrary data in an "extensions" error field:

  "errors": [
    {
      "message": "Name for character with ID 1002 could not be fetched.",
      "locations": [ { "line": 6, "column": 7 } ],
      "path": [ "hero", "heroFriends", 1, "name" ],
      "extensions": {
        "code": "CAN_NOT_FETCH_BY_ID",
        "timestamp": "Fri Feb 9 14:33:09 UTC 2018"
      }
    }
  ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.