code: func checkResponseCode(r *http.Response) error {
  	if r.StatusCode >= 200 && r.StatusCode < 300 {
  		return nil
  	}
  
  	rErr := &apitypes.Error{Type: apitypes.LookupErrorType(r.StatusCode)}
  	if r.ContentLength != 0 {
  		dec := json.NewDecoder(r.Body)
  		err := dec.Decode(rErr)
  		if err != nil {
  			return errBadResponse
  		}
  
  		return rErr
  	}
  
  	return fmt.Errorf("unknown error response from server with status code %d",
  		r.StatusCode)
  }
docs: // checkReponseCode checks if the response from the server is an error,
  // and if so, attempts to marshal the response into the error type.