forked from machinebox/graphql
-
Notifications
You must be signed in to change notification settings - Fork 1
/
error.go
62 lines (52 loc) · 1.75 KB
/
error.go
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package graphql
import (
"bytes"
"errors"
"fmt"
)
const (
errNotFound graphErrType = "not_found"
errNotAllowed graphErrType = "not_allowed"
errInvalidInput graphErrType = "invalid_input"
errCapacityExceeded graphErrType = "capacity_exceeded"
errAuthentication graphErrType = "authentication_error"
errImplemented graphErrType = "not_implemented"
errServiceUnavailable graphErrType = "service_unavailable"
errServiceFailure graphErrType = "service_failure"
errInternal graphErrType = "internal_error"
)
type graphErr struct {
Message string `json:"message,omitempty"`
Name graphErrType `json:"name,omitempty"`
TimeThrown string `json:"time_thrown,omitempty"`
Data interface{} `json:"data,omitempty"`
Path []interface{} `json:"path,omitempty"`
Locations []graphErrLoc `json:"locations,omitempty"`
}
type graphErrData struct {
ObjectID string `json:"objectId,omitempty"`
ObjectType string `json:"objectType,omitempty"`
ErrorID string `json:"errorId,omitempty"`
RequestID string `json:"requestId,omitempty"`
}
type graphErrLoc struct {
Line int64 `json:"line"`
Column int64 `json:"column"`
}
type graphErrType string
func getAggrErr(errList []graphErr) error {
var buffer bytes.Buffer
buffer.WriteString("graphql: ")
for idx, err := range errList {
buffer.WriteString(fmt.Sprintf("error %d: name (%s), message (%s), data (%+v). ", idx, err.Name, err.Message, err.Data))
}
return errors.New(buffer.String())
}
func shouldRetry(errList []graphErr) bool {
for _, err := range errList {
if err.Name == errCapacityExceeded || err.Name == errServiceUnavailable || err.Name == errServiceFailure || err.Name == errInternal {
return true
}
}
return false
}