-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors.go
More file actions
80 lines (66 loc) · 1.89 KB
/
errors.go
File metadata and controls
80 lines (66 loc) · 1.89 KB
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
73
74
75
76
77
78
79
80
package xposedornot
import "fmt"
// ErrRateLimit is returned when the API returns a 429 Too Many Requests
// response after all retries have been exhausted.
type ErrRateLimit struct {
Message string
}
func (e *ErrRateLimit) Error() string {
if e.Message != "" {
return fmt.Sprintf("rate limit exceeded: %s", e.Message)
}
return "rate limit exceeded"
}
// ErrNotFound is returned when the requested resource is not found (404).
type ErrNotFound struct {
Resource string
}
func (e *ErrNotFound) Error() string {
if e.Resource != "" {
return fmt.Sprintf("not found: %s", e.Resource)
}
return "not found"
}
// ErrAuthentication is returned when the API returns a 401 or 403 response,
// typically due to a missing or invalid API key.
type ErrAuthentication struct {
Message string
}
func (e *ErrAuthentication) Error() string {
if e.Message != "" {
return fmt.Sprintf("authentication failed: %s", e.Message)
}
return "authentication failed"
}
// ErrValidation is returned when input validation fails on the client side,
// such as an invalid email address format.
type ErrValidation struct {
Field string
Message string
}
func (e *ErrValidation) Error() string {
if e.Field != "" {
return fmt.Sprintf("validation error on %s: %s", e.Field, e.Message)
}
return fmt.Sprintf("validation error: %s", e.Message)
}
// ErrNetwork is returned when a network-level error occurs, such as a
// connection timeout or DNS resolution failure.
type ErrNetwork struct {
Err error
}
func (e *ErrNetwork) Error() string {
return fmt.Sprintf("network error: %v", e.Err)
}
func (e *ErrNetwork) Unwrap() error {
return e.Err
}
// ErrAPI is returned when the API returns an unexpected error response
// that does not map to a more specific error type.
type ErrAPI struct {
StatusCode int
Body string
}
func (e *ErrAPI) Error() string {
return fmt.Sprintf("api error (status %d): %s", e.StatusCode, e.Body)
}