Skip to content

Commit

Permalink
Add ResolverError field to QueryError for post processing
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick Randall committed Jan 11, 2017
1 parent b7c59ab commit 24b2045
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
5 changes: 3 additions & 2 deletions errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ package errors
import "fmt"

type QueryError struct {
Message string `json:"message"`
Locations []*Location `json:"locations,omitempty"`
Message string `json:"message"`
Locations []*Location `json:"locations,omitempty"`
ResolverError error `json:"-"`
}

type Location struct {
Expand Down
7 changes: 6 additions & 1 deletion internal/exec/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,9 @@ func (r *request) addError(err *errors.QueryError) {
func (r *request) handlePanic() {
if err := recover(); err != nil {
execErr := errors.Errorf("graphql: panic occured: %v", err)
if err, ok := err.(error); ok {
execErr.ResolverError = err
}
r.addError(execErr)

const size = 64 << 10
Expand Down Expand Up @@ -554,7 +557,9 @@ func (e *fieldExec) execField(ctx context.Context, r *request, f *query.Field, r
result, err := e.execField2(spanCtx, r, f, resolver, span)

if err != nil {
r.addError(errors.Errorf("%s", err))
queryError := errors.Errorf("%s", err)
queryError.ResolverError = err
r.addError(queryError)
addResult(f.Alias, nil) // TODO handle non-nil

ext.Error.Set(span, true)
Expand Down

0 comments on commit 24b2045

Please sign in to comment.