-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.go
65 lines (58 loc) · 1.33 KB
/
utils.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
63
64
65
package enthasura
import (
"github.com/minskylab/hasura-api/metadata"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)
func elementInArray(array []string, element string) bool {
for _, el := range array {
if el == element {
return true
}
}
return false
}
func logAndResponseMetadataResponse(res metadata.MetadataResponse, soft bool) error {
if res == nil {
if soft {
return nil
}
return errors.New("metadata response is nil")
}
switch response := res.(type) {
case metadata.RestyResponse:
logrus.WithFields(logrus.Fields{
"status": response.StatusCode(),
"body": string(response.Body()),
"url": response.Request.URL,
}).Debug("metadata response")
}
// switch msg := res.(type) {
// case metadata.ObjectResponse, metadata.ArrayResponse:
// logrus.Debug(msg)
// return nil
// case metadata.MetadataResponses:
// logrus.Debug(msg)
// case metadata.BadRequestResponse:
// logrus.Error(msg)
// if soft {
// return nil
// }
// return errors.New(msg.Error)
// case metadata.InternalServerErrorResponse:
// logrus.Error(msg)
// if soft {
// return nil
// }
// return errors.New(msg.Error)
// case metadata.UnauthorizedResponse:
// logrus.Error(msg)
// if soft {
// return nil
// }
// return errors.New(msg.Error)
// default:
// logrus.Warn(msg)
// }
return nil
}