-
Notifications
You must be signed in to change notification settings - Fork 10
/
errors.go
72 lines (56 loc) · 1.68 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
71
72
package statsig
import (
"errors"
"fmt"
)
// Error Variables
type StatsigError error
var (
ErrNetworkRequest StatsigError = errors.New("failed network request")
ErrFailedLogEvent StatsigError = errors.New("failed to log events")
ErrDataAdapter StatsigError = errors.New("failed data adapter")
)
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 }
func (e *TransportError) Is(target error) bool { return target == ErrNetworkRequest }
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 }
type DataAdapterError struct {
Err error
Method string
}
func (e *DataAdapterError) Error() string {
if e.Err != nil {
return fmt.Sprintf("Error calling data adapter %s: %s", e.Method, e.Err.Error())
} else {
return fmt.Sprintf("Error calling data adapter %s", e.Method)
}
}
func (e *DataAdapterError) Unwrap() error { return e.Err }
func (e *DataAdapterError) Is(target error) bool { return target == ErrDataAdapter }