forked from galaxydi/go-loghub
-
Notifications
You must be signed in to change notification settings - Fork 113
/
errors.go
43 lines (36 loc) · 951 Bytes
/
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
package sls
import (
"encoding/json"
)
// BadResponseError : special sls error, not valid json format
type BadResponseError struct {
RespBody string
RespHeader map[string][]string
HTTPCode int
}
func (e BadResponseError) String() string {
b, err := json.MarshalIndent(e, "", " ")
if err != nil {
return ""
}
return string(b)
}
func (e BadResponseError) Error() string {
return e.String()
}
// NewBadResponseError ...
func NewBadResponseError(body string, header map[string][]string, httpCode int) *BadResponseError {
return &BadResponseError{
RespBody: body,
RespHeader: header,
HTTPCode: httpCode,
}
}
// mockErrorRetry : for mock the error retry logic
type mockErrorRetry struct {
Err Error
RetryCnt int // RetryCnt-- after each retry. When RetryCnt > 0, return Err, else return nil, if set it BigUint, it equivalents to always failing.
}
func (e mockErrorRetry) Error() string {
return e.Err.String()
}