-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy patherror.go
More file actions
executable file
·38 lines (30 loc) · 818 Bytes
/
error.go
File metadata and controls
executable file
·38 lines (30 loc) · 818 Bytes
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
34
35
36
37
38
package graphql
import "strings"
// Error represents a graphql error
type Error struct {
Extensions map[string]interface{} `json:"extensions"`
Message string `json:"message"`
Path []interface{} `json:"path,omitempty"`
}
func (e *Error) Error() string {
return e.Message
}
// NewError returns a graphql error with the given code and message
func NewError(code string, message string) *Error {
return &Error{
Message: message,
Extensions: map[string]interface{}{
"code": code,
},
}
}
// ErrorList represents a list of errors
type ErrorList []error
// Error returns a string representation of each error
func (list ErrorList) Error() string {
acc := []string{}
for _, error := range list {
acc = append(acc, error.Error())
}
return strings.Join(acc, ". ")
}