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