Files
stash/vendor/github.com/99designs/gqlgen/graphql/error.go
WithoutPants bba7c23957 Upgrade to go 1.19 and update dependencies (#3069)
* Update to go 1.19
* Update dependencies
* Update cross-compile script
* Add missing targets to cross-compile-all
* Update cache action to remove warning
2022-11-04 13:41:26 +11:00

34 lines
716 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 the original error to avoid losing any attached annotation
return err
}
return gqlerror.WrapPath(GetPath(ctx), err)
}