code: func checkResponse(r *http.Response) error {
  	if c := r.StatusCode; c >= 200 && c <= 299 {
  		return nil
  	}
  
  	apiErr := &APIError{Response: r}
  	data, err := ioutil.ReadAll(r.Body)
  	if err == nil && len(data) > 0 {
  		type E struct {
  			Error *APIError `json:"error"`
  		}
  		e := E{}
  		if err = json.Unmarshal(data, &e); err == nil {
  			e.Error.Response = r
  			apiErr = e.Error
  		}
  	}
  	return apiErr
  }
docs: // CheckResponse checks the API response for errors, and returns them if present. A response is considered an
  // error if it has a status code outside the 200 range. API error responses are expected to have either no response
  // body, or a JSON response body that maps to APIError.