1 MiB bareDo sends an API request using `caller` http.Client passed in the parameters and lets you handle the api response. If an error or API Error occurs, the error will contain more information. Otherwise, you are supposed to read and close the response's Body. If rate limit is exceeded and reset
(caller *http.Client, req *http.Request)
| 1149 | // response's Body. If rate limit is exceeded and reset time is in the future, |
| 1150 | // bareDo returns *RateLimitError immediately without making a network API call. |
| 1151 | func (c *Client) bareDo(caller *http.Client, req *http.Request) (*Response, error) { |
| 1152 | ctx := req.Context() |
| 1153 | |
| 1154 | rateLimitCategory := CoreCategory |
| 1155 | |
| 1156 | if !c.disableRateLimitCheck { |
| 1157 | rateLimitCategory = GetRateLimitCategory(req.Method, req.URL.Path) |
| 1158 | |
| 1159 | if bypass := ctx.Value(BypassRateLimitCheck); bypass == nil { |
| 1160 | // If we've hit rate limit, don't make further requests before Reset time. |
| 1161 | if err := c.checkRateLimitBeforeDo(req, rateLimitCategory); err != nil { |
| 1162 | return &Response{ |
| 1163 | Response: err.Response, |
| 1164 | Rate: err.Rate, |
| 1165 | }, err |
| 1166 | } |
| 1167 | |
| 1168 | // If we've hit a secondary rate limit, don't make further requests before Retry After. |
| 1169 | if err := c.checkSecondaryRateLimitBeforeDo(req); err != nil { |
| 1170 | return &Response{ |
| 1171 | Response: err.Response, |
| 1172 | }, err |
| 1173 | } |
| 1174 | } |
| 1175 | } |
| 1176 | |
| 1177 | resp, err := caller.Do(req) |
| 1178 | var response *Response |
| 1179 | if resp != nil { |
| 1180 | response = newResponse(resp) |
| 1181 | } |
| 1182 | |
| 1183 | if err != nil { |
| 1184 | // If we got an error, and the context has been canceled, |
| 1185 | // the context's error is probably more useful. |
| 1186 | select { |
| 1187 | case <-ctx.Done(): |
| 1188 | return response, ctx.Err() |
| 1189 | default: |
| 1190 | } |
| 1191 | |
| 1192 | // If the error type is *url.Error, sanitize its URL before returning. |
| 1193 | var e *url.Error |
| 1194 | if errors.As(err, &e) { |
| 1195 | if url, err := url.Parse(e.URL); err == nil { |
| 1196 | e.URL = sanitizeURL(url).String() |
| 1197 | return response, e |
| 1198 | } |
| 1199 | } |
| 1200 | |
| 1201 | return response, err |
| 1202 | } |
| 1203 | |
| 1204 | // Don't update the rate limits if the client has rate limits disabled or if |
| 1205 | // this was a cached response. The X-From-Cache is set by |
| 1206 | // https://github.com/bartventer/httpcache if it's enabled. |
| 1207 | if !c.disableRateLimitCheck && response.Header.Get("X-From-Cache") == "" { |
| 1208 | c.rateMu.Lock() |
no test coverage detected