@@ -50,14 +50,23 @@ type Client struct {
50
50
}
51
51
52
52
const (
53
- errNoNoError = 0
54
- errNoTokenExpired = 41808
55
- errNoTokenInvalid = 41809
56
- errHeadersMissing = 40256
57
- errBodyInvalid = 40257
58
- errRateLimit = 40400
53
+ errNoNoError = 0
54
+ errNoTokenExpired = 41808
55
+ errNoTokenInvalid = 41809
56
+ errHeadersMissing = 40256
57
+ errBodyInvalid = 40257
58
+ errRequestsTooFrequent = 40400
59
+ errRateLimitExceeded = 40402
59
60
)
60
61
62
+ type RateLimitExceededError struct {
63
+ msg string
64
+ }
65
+
66
+ func (e * RateLimitExceededError ) Error () string {
67
+ return fmt .Sprintf ("rate limit exceeded: %s" , e .msg )
68
+ }
69
+
61
70
type errorResponse struct {
62
71
ErrNo int `json:"errno"`
63
72
Msg string `json:"msg"`
@@ -89,8 +98,10 @@ func (c *Client) do(req *http.Request, res any) (*http.Response, error) {
89
98
return nil , fmt .Errorf ("missing headers: %v" , errResp .Msg )
90
99
case errBodyInvalid :
91
100
return nil , fmt .Errorf ("invalid body: %v" , errResp .Msg )
92
- case errRateLimit :
101
+ case errRequestsTooFrequent :
93
102
return nil , fmt .Errorf ("rate limit exceeded: %v" , errResp .Msg )
103
+ case errRateLimitExceeded :
104
+ return nil , & RateLimitExceededError {msg : errResp .Msg }
94
105
default :
95
106
return nil , fmt .Errorf ("invalid response, got error code: %v, message: %v" , errResp .ErrNo , errResp .Msg )
96
107
}
0 commit comments