Skip to content

Commit 330622f

Browse files
committed
Expose RateLimitExceededError.
1 parent f7431b9 commit 330622f

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

client.go

+18-7
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,23 @@ type Client struct {
5050
}
5151

5252
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
5960
)
6061

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+
6170
type errorResponse struct {
6271
ErrNo int `json:"errno"`
6372
Msg string `json:"msg"`
@@ -89,8 +98,10 @@ func (c *Client) do(req *http.Request, res any) (*http.Response, error) {
8998
return nil, fmt.Errorf("missing headers: %v", errResp.Msg)
9099
case errBodyInvalid:
91100
return nil, fmt.Errorf("invalid body: %v", errResp.Msg)
92-
case errRateLimit:
101+
case errRequestsTooFrequent:
93102
return nil, fmt.Errorf("rate limit exceeded: %v", errResp.Msg)
103+
case errRateLimitExceeded:
104+
return nil, &RateLimitExceededError{msg: errResp.Msg}
94105
default:
95106
return nil, fmt.Errorf("invalid response, got error code: %v, message: %v", errResp.ErrNo, errResp.Msg)
96107
}

0 commit comments

Comments
 (0)