checkRespErr checks if the given http response indicates an error. It returns a boolean indicating if the response is an error, and a decoded error message.
(res *http.Response)
| 139 | // checkRespErr checks if the given http response indicates an error. It returns a boolean indicating |
| 140 | // if the response is an error, and a decoded error message. |
| 141 | func checkRespErr(res *http.Response) error { |
| 142 | if res.StatusCode < 400 { |
| 143 | return nil |
| 144 | } |
| 145 | |
| 146 | body, err := io.ReadAll(res.Body) |
| 147 | if err != nil { |
| 148 | return errors.Wrapf(err, "server responded with %d but client could not read the response body", res.StatusCode) |
| 149 | } |
| 150 | |
| 151 | bodyStr := string(body) |
| 152 | return &HTTPError{ |
| 153 | StatusCode: res.StatusCode, |
| 154 | Message: strings.TrimRight(bodyStr, "\n"), |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | func checkContentType(res *http.Response, options *requestOptions) error { |
| 159 | expected := getExpectedContentType(options) |