| 319 | } |
| 320 | |
| 321 | func handleHTTPError(resp *http.Response) error { |
| 322 | httpError := httpError{ |
| 323 | RequestURL: resp.Request.URL, |
| 324 | StatusCode: resp.StatusCode, |
| 325 | } |
| 326 | if !jsonTypeRE.MatchString(resp.Header.Get("Content-Type")) { |
| 327 | httpError.Message = resp.Status |
| 328 | return httpError |
| 329 | } |
| 330 | body, err := io.ReadAll(resp.Body) |
| 331 | if err != nil { |
| 332 | return err |
| 333 | } |
| 334 | if err := json.Unmarshal(body, &httpError); err != nil { |
| 335 | return err |
| 336 | } |
| 337 | return httpError |
| 338 | } |
| 339 | |
| 340 | // nextPage extracts the next page number from an API response's link header. if |
| 341 | // the provided link header is empty or there is no next page, zero is returned. |