expect2XX will doReqGated and promote HTTP response codes outside of the 200-299 range to a non-nil error containing the response body.
(req *http.Request)
| 1216 | // expect2XX will doReqGated and promote HTTP response codes outside of |
| 1217 | // the 200-299 range to a non-nil error containing the response body. |
| 1218 | func (c *Client) expect2XX(req *http.Request) (*http.Response, error) { |
| 1219 | res, err := c.doReqGated(req) |
| 1220 | if err == nil && (res.StatusCode < 200 || res.StatusCode > 299) { |
| 1221 | buf := new(bytes.Buffer) |
| 1222 | io.CopyN(buf, res.Body, 1<<20) |
| 1223 | res.Body.Close() |
| 1224 | return res, fmt.Errorf("client: got status code %d from URL %s; body %s", res.StatusCode, req.URL.String(), buf.String()) |
| 1225 | } |
| 1226 | return res, err |
| 1227 | } |
| 1228 | |
| 1229 | func (c *Client) doReqGated(req *http.Request) (*http.Response, error) { |
| 1230 | c.httpGate.Start() |
no test coverage detected