Skip to content

Commit

Permalink
Fixes #1653: update docs and wrap error if not *gqlerror.Error
Browse files Browse the repository at this point in the history
Signed-off-by: Steve Coffman <steve@khanacademy.org>
  • Loading branch information
StevenACoffman committed Oct 10, 2021
1 parent a3d9e8c commit 5cc337e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion docs/content/reference/errors.md
Expand Up @@ -114,7 +114,7 @@ server := handler.NewDefaultServer(MakeExecutableSchema(resolvers)
server.SetRecoverFunc(func(ctx context.Context, err interface{}) error {
// notify bug tracker...

return errors.New("Internal server error!")
return gqlerror.Errorf("Internal server error!")
})
```

17 changes: 11 additions & 6 deletions graphql/error.go
Expand Up @@ -10,19 +10,24 @@ import (
type ErrorPresenterFunc func(ctx context.Context, err error) *gqlerror.Error

func DefaultErrorPresenter(ctx context.Context, err error) *gqlerror.Error {
return err.(*gqlerror.Error)
var gqlErr *gqlerror.Error
if errors.As(err, &gqlErr) {
return gqlErr
}
gqlErr = gqlerror.WrapPath(nil, err)
return gqlErr
}

func ErrorOnPath(ctx context.Context, err error) error {
if err == nil {
return nil
}
var gqlerr *gqlerror.Error
if errors.As(err, &gqlerr) {
if gqlerr.Path == nil {
gqlerr.Path = GetPath(ctx)
var gqlErr *gqlerror.Error
if errors.As(err, &gqlErr) {
if gqlErr.Path == nil {
gqlErr.Path = GetPath(ctx)
}
return gqlerr
return gqlErr
}
return gqlerror.WrapPath(GetPath(ctx), err)
}

0 comments on commit 5cc337e

Please sign in to comment.