forked from statsig-io/go-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors.go
51 lines (40 loc) · 1.03 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
package statsig
import (
"errors"
"fmt"
)
// Error Variables
type StatsigError error
var (
ErrFailedLogEvent StatsigError = errors.New("failed to log events")
)
type RequestMetadata struct {
StatusCode int
Endpoint string
Retries int
}
type TransportError struct {
RequestMetadata *RequestMetadata
Err error
}
func (e *TransportError) Error() string {
if e.RequestMetadata != nil {
return fmt.Sprintf("Failed request to %s after %d retries: %s", e.RequestMetadata.Endpoint, e.RequestMetadata.Retries, e.Err.Error())
} else {
return e.Err.Error()
}
}
func (e *TransportError) Unwrap() error { return e.Err }
type LogEventError struct {
Err error
Events int
}
func (e *LogEventError) Error() string {
if e.Err != nil {
return fmt.Sprintf("Failed to log %d events: %s", e.Events, e.Err.Error())
} else {
return fmt.Sprintf("Failed to log %d events", e.Events)
}
}
func (e *LogEventError) Unwrap() error { return e.Err }
func (e *LogEventError) Is(target error) bool { return target == ErrFailedLogEvent }