func ResponseError(resp *http.Response) error {
	if resp.StatusCode < 400 {
		return nil
	}
	defer func() { _ = resp.Body.Close() }()
	httpErr := &HTTPError{}
	if resp.Request.Method != "HEAD" && resp.ContentLength != 0 {
		if ct, _, _ := mime.ParseMediaType(resp.Header.Get("Content-Type")); ct == typeJSON {
			if err := json.NewDecoder(resp.Body).Decode(httpErr); err != nil {
				httpErr.Reason = fmt.Sprintf("unknown (failed to decode error response: %s)", err)
			}
		}
	}
	httpErr.Code = resp.StatusCode
	return httpErr
}
// ResponseError returns an error from an *http.Response.
ResponseError returns an error from an *http.Response.
// ResponseError returns an error from an * http . Response .
func ResponseError(resp *http.Response) error {
	if resp.StatusCode < 400 {
		return nil
	}
	defer func() { _ = resp.Body.Close() }()
	httpErr := &HTTPError{}
	if resp.Request.Method != "HEAD" && resp.ContentLength != 0 {
		if ct, _, _ := mime.ParseMediaType(resp.Header.Get("Content-Type")); ct == typeJSON {
			if err := json.NewDecoder(resp.Body).Decode(httpErr); err != nil {
				httpErr.Reason = fmt.Sprintf("unknown (failed to decode error response: %s)", err)
			}
		}
	}
	httpErr.Code = resp.StatusCode
	return httpErr
}
func ResponseError ( resp * http . Response ) error { if resp . StatusCode < 400 { return nil } defer func ( ) { _ = resp . Body . Close ( ) } ( ) httpErr := & HTTPError { } if resp . Request . Method != " " && resp . ContentLength != 0 { if ct , _ , _ := mime . ParseMediaType ( resp . Header . Get ( " " ) ) ; ct == typeJSON { if err := json . NewDecoder ( resp . Body ) . Decode ( httpErr ) ; err != nil { httpErr . Reason = fmt . Sprintf ( " " , err ) } } } httpErr . Code = resp . StatusCode return httpErr }
ResponseError returns an error from an *http.Response.
ResponseError returns an error from an * http . Response .