func (r *Response) Error() error {
	if r.StatusCode >= 200 && r.StatusCode < 400 {
		return nil
	}
	var bodyBuf bytes.Buffer
	if _, err := io.Copy(&bodyBuf, r.Body); err != nil {
		return err
	}
	var resp ErrorResponse
	if err := jsonutil.DecodeJSON(bodyBuf.Bytes(), &resp); err != nil {
		return fmt.Errorf(
			"Error making API request.\n\n"+
				"URL: %s %s\n"+
				"Code: %d. Raw Message:\n\n%s",
			r.Request.Method, r.Request.URL.String(),
			r.StatusCode, bodyBuf.String())
	}
	var errBody bytes.Buffer
	errBody.WriteString(fmt.Sprintf(
		"Error making API request.\n\n"+
			"URL: %s %s\n"+
			"Code: %d. Errors:\n\n",
		r.Request.Method, r.Request.URL.String(),
		r.StatusCode))
	for _, err := range resp.Errors {
		errBody.WriteString(fmt.Sprintf("* %s", err))
	}
	return fmt.Errorf(errBody.String())
}
Error returns an error response if there is one. If there is an error,
this will fully consume the response body, but will not close it. The
body must still be closed manually.
package api
import (
	"bytes"
	"fmt"
	"io"
	"net/http"
	"github.com/hashicorp/vault/helper/jsonutil"
)
type Response struct {
	*http.Response
}
func (r *Response) DecodeJSON(out interface{}) error {
	return jsonutil.DecodeJSONFromReader(r.Body, out)
}