blob: af8b4ce4088107d6aafb5366cec71fc54bc8a57c (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
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 {
if gqlerr.Path == nil {
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,
}
}
|