Esempio n. 1
0
func googleError(r *httpclient.Response) error {
	data, _ := r.ReadAll()
	var e *Error
	if err := json.Unmarshal(data, &e); err == nil && e != nil && e.Message != "" {
		return e
	}
	return fmt.Errorf("invalid status code %d: %s", r.StatusCode, string(data))
}
Esempio n. 2
0
func (c *Client) decodeError(r *httpclient.Response) error {
	if c.DecodeError != nil {
		return c.DecodeError(r)
	}
	data, err := r.ReadAll()
	if err != nil {
		return fmt.Errorf("error reading response: %s", err)
	}
	return errors.New(string(data))
}
Esempio n. 3
0
func parseToken(resp *httpclient.Response) (*Token, error) {
	defer resp.Close()
	b, err := resp.ReadAll()
	if err != nil {
		return nil, err
	}
	s := string(b)
	if !resp.IsOK() {
		return nil, fmt.Errorf("oAuth service returned non-200 status code %d: %s", resp.StatusCode, s)
	}
	values, err := url.ParseQuery(s)
	if err != nil {
		return nil, err
	}
	key := values.Get("oauth_token")
	secret := values.Get("oauth_token_secret")
	if key == "" || secret == "" {
		return nil, fmt.Errorf("can't parse token from %q", s)
	}
	return &Token{
		Key:    key,
		Secret: secret,
	}, nil
}