github.com/buth/gqlgen@v0.7.2/graphql/error.go (about) 1 package graphql 2 3 import ( 4 "context" 5 6 "github.com/vektah/gqlparser/gqlerror" 7 ) 8 9 type ErrorPresenterFunc func(context.Context, error) *gqlerror.Error 10 11 type ExtendedError interface { 12 Extensions() map[string]interface{} 13 } 14 15 func DefaultErrorPresenter(ctx context.Context, err error) *gqlerror.Error { 16 if gqlerr, ok := err.(*gqlerror.Error); ok { 17 gqlerr.Path = GetResolverContext(ctx).Path() 18 return gqlerr 19 } 20 21 var extensions map[string]interface{} 22 if ee, ok := err.(ExtendedError); ok { 23 extensions = ee.Extensions() 24 } 25 26 return &gqlerror.Error{ 27 Message: err.Error(), 28 Path: GetResolverContext(ctx).Path(), 29 Extensions: extensions, 30 } 31 }