Files
stash/vendor/github.com/99designs/gqlgen/graphql/error.go
2022-11-07 12:33:15 +11:00

33 lines
648 B
Go

package graphql
import (
"context"
"errors"
"github.com/vektah/gqlparser/v2/gqlerror"
)
type ErrorPresenterFunc func(ctx context.Context, err error) *gqlerror.Error
func DefaultErrorPresenter(ctx context.Context, err error) *gqlerror.Error {
var gqlErr *gqlerror.Error
if errors.As(err, &gqlErr) {
return gqlErr
}
return gqlerror.WrapPath(GetPath(ctx), err)
}
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)
}
return gqlErr
}
return gqlerror.WrapPath(GetPath(ctx), err)
}