aboutsummaryrefslogblamecommitdiffstats
path: root/vendor/github.com/99designs/gqlgen/graphql/error.go
blob: 7f161a4306bd780f3268a9f255ed75a68b577a56 (plain) (tree)






























                                                                            
package graphql

import (
	"context"

	"github.com/vektah/gqlparser/gqlerror"
)

type ErrorPresenterFunc func(context.Context, error) *gqlerror.Error

type ExtendedError interface {
	Extensions() map[string]interface{}
}

func DefaultErrorPresenter(ctx context.Context, err error) *gqlerror.Error {
	if gqlerr, ok := err.(*gqlerror.Error); ok {
		gqlerr.Path = GetResolverContext(ctx).Path()
		return gqlerr
	}

	var extensions map[string]interface{}
	if ee, ok := err.(ExtendedError); ok {
		extensions = ee.Extensions()
	}

	return &gqlerror.Error{
		Message:    err.Error(),
		Path:       GetResolverContext(ctx).Path(),
		Extensions: extensions,
	}
}