| 105 | } |
| 106 | |
| 107 | func (cli *Client) sendRequest(ctx context.Context, method, path string, query url.Values, body io.Reader, headers http.Header) (*http.Response, error) { |
| 108 | req, err := cli.buildRequest(ctx, method, cli.getAPIPath(ctx, path, query), body, headers) |
| 109 | if err != nil { |
| 110 | return nil, err |
| 111 | } |
| 112 | |
| 113 | resp, err := cli.doRequest(req) |
| 114 | if err != nil { |
| 115 | // Failed to connect or context error. |
| 116 | return resp, err |
| 117 | } |
| 118 | |
| 119 | // Successfully made a request; return the response and handle any |
| 120 | // API HTTP response errors. |
| 121 | return resp, checkResponseErr(resp) |
| 122 | } |
| 123 | |
| 124 | // doRequest sends an HTTP request and returns an HTTP response. It is a |
| 125 | // wrapper around [http.Client.Do] with extra handling to decorate errors. |