// responseError creates an error of Error type from resp.
responseError creates an error of Error type from resp.
// responseError creates an error of Error type from resp .
func responseError(resp *http.Response) error {
	b, _ := ioutil.ReadAll(resp.Body)
	e := struct {
		Status int
		Type   string
		Detail string
	}{
		Status: resp.StatusCode,
	}
	if err := json.Unmarshal(b, &e); err != nil {
		e.Detail = string(b)
		if e.Detail == "" {
			e.Detail = resp.Status
		}
	}
	return &Error{
		StatusCode:  e.Status,
		ProblemType: e.Type,
		Detail:      e.Detail,
		Header:      resp.Header,
	}
}
func responseError ( resp * http . Response ) error { b , _ := ioutil . ReadAll ( resp . Body ) e := struct { Status int Type string Detail string } { Status : resp . StatusCode , } if err := json . Unmarshal ( b , & e ) ; err != nil { e . Detail = string ( b ) if e . Detail == " " { e . Detail = resp . Status } } return & Error { StatusCode : e . Status , ProblemType : e . Type , Detail : e . Detail , Header : resp . Header , } }
responseError creates an error of Error type from resp.
responseError creates an error of Error type from resp .
// don't care if ReadAll returns an error: // json.Unmarshal will fail in that case anyway // this is not a regular error response: // populate detail with anything we received, // e.Status will already contain HTTP response code value