-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors.go
70 lines (62 loc) · 1.89 KB
/
errors.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
66
67
68
69
70
package chalk
import (
"fmt"
"strings"
)
func (e *ErrorResponse) Error() string {
if len(e.ServerErrors) > 0 {
stringifiedServerErrors := make([]string, 0)
for _, err := range e.ServerErrors {
stringifiedServerErrors = append(stringifiedServerErrors, err.Error())
}
return strings.Join(stringifiedServerErrors, "\n")
} else if e.HttpError != nil {
return e.HttpError.Error()
} else if e.ClientError != nil {
return e.ClientError.Error()
} else {
return "Unexpected chalk.Client error. Please contact Chalk if this persists."
}
}
func (e *ClientError) Error() string {
return e.Message
}
func (e *ServerError) Error() string {
detailArr := make([]string, 0)
if e.Message != "" {
detailArr = append(detailArr, "Message: "+e.Message)
}
if e.Exception != nil && e.Exception.Message != "" {
detailArr = append(detailArr, "Exception: "+e.Exception.Message)
}
if e.Exception != nil && e.Exception.Stacktrace != "" {
detailArr = append(detailArr, "Stacktrace: "+e.Exception.Stacktrace)
}
if e.Resolver != "" {
detailArr = append(detailArr, "Resolver: "+e.Resolver)
}
if e.Feature != "" {
detailArr = append(detailArr, "Feature: "+e.Feature)
}
details := ""
if len(detailArr) > 0 {
contents := strings.Join(detailArr, " | ")
details = ": [ " + contents + " ]"
}
return fmt.Sprintf("Chalk Error occurred%s", details)
}
func (e *HTTPError) Error() string {
if e.Trace != nil {
return fmt.Sprintf("HTTP Error: path=%q, message=%q, status=%d, content-length=%d, trace=%q",
e.Path, e.Message, e.StatusCode, e.ContentLength, *e.Trace)
}
return fmt.Sprintf("HTTP Error: path=%q, message=%q, status=%d, content-length=%d",
e.Path, e.Message, e.StatusCode, e.ContentLength)
}
func deferFunctionWithError(function func() error, originalError error) error {
err := originalError
if bodyCloseErr := function(); bodyCloseErr != nil && err == nil {
err = bodyCloseErr
}
return err
}