-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors.go
More file actions
83 lines (69 loc) · 2.12 KB
/
errors.go
File metadata and controls
83 lines (69 loc) · 2.12 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
81
82
83
package moderyo
import "fmt"
// ModeryoError is the interface all SDK errors implement.
type ModeryoError interface {
error
ErrorCode() string
}
// APIError represents a generic API error.
type APIError struct {
Code string
Message string
StatusCode int
RequestID string
}
func (e *APIError) Error() string {
return fmt.Sprintf("moderyo: API error %d: %s", e.StatusCode, e.Message)
}
func (e *APIError) ErrorCode() string { return e.Code }
// AuthenticationError represents a 401 error.
type AuthenticationError struct {
Message string
RequestID string
}
func (e *AuthenticationError) Error() string {
return fmt.Sprintf("moderyo: authentication error: %s", e.Message)
}
func (e *AuthenticationError) ErrorCode() string { return "AUTHENTICATION_ERROR" }
// RateLimitError represents a 429 error.
type RateLimitError struct {
Message string
RetryAfter float64
Limit int
Remaining int
RequestID string
}
func (e *RateLimitError) Error() string {
return fmt.Sprintf("moderyo: rate limit exceeded: %s (retry after %.0fs)", e.Message, e.RetryAfter)
}
func (e *RateLimitError) ErrorCode() string { return "RATE_LIMIT_ERROR" }
// ValidationError represents a 400/422 error.
type ValidationError struct {
Message string
Field string
RequestID string
}
func (e *ValidationError) Error() string {
return fmt.Sprintf("moderyo: validation error: %s", e.Message)
}
func (e *ValidationError) ErrorCode() string { return "VALIDATION_ERROR" }
// QuotaExceededError represents a 402 error.
type QuotaExceededError struct {
Message string
RequestID string
}
func (e *QuotaExceededError) Error() string {
return fmt.Sprintf("moderyo: quota exceeded: %s", e.Message)
}
func (e *QuotaExceededError) ErrorCode() string { return "QUOTA_EXCEEDED_ERROR" }
// NetworkError represents connection/DNS/timeout errors.
type NetworkError struct {
Message string
IsTimeout bool
Cause error
}
func (e *NetworkError) Error() string {
return fmt.Sprintf("moderyo: network error: %s", e.Message)
}
func (e *NetworkError) ErrorCode() string { return "NETWORK_ERROR" }
func (e *NetworkError) Unwrap() error { return e.Cause }