| 296 | } |
| 297 | |
| 298 | func handleHTTPError(resp *http.Response) error { |
| 299 | httpError := httpError{ |
| 300 | RequestURL: resp.Request.URL, |
| 301 | StatusCode: resp.StatusCode, |
| 302 | } |
| 303 | if !jsonTypeRE.MatchString(resp.Header.Get("Content-Type")) { |
| 304 | httpError.Message = resp.Status |
| 305 | return httpError |
| 306 | } |
| 307 | body, err := io.ReadAll(resp.Body) |
| 308 | if err != nil { |
| 309 | return err |
| 310 | } |
| 311 | if err := json.Unmarshal(body, &httpError); err != nil { |
| 312 | return err |
| 313 | } |
| 314 | return httpError |
| 315 | } |
| 316 | |
| 317 | // nextPage extracts the next page number from an API response's link header. if |
| 318 | // the provided link header is empty or there is no next page, zero is returned. |