code: func NewHTTPError(resp *http.Response) *HTTPError {
  	var e HTTPError
  	e.StatusCode = resp.StatusCode
  
  	if resp.Body == nil {
  		return &e
  	}
  
  	// If this is a jsonapi response, decode it accordingly
  	if resp.Header.Get("Content-Type") == jsonapi.MediaType {
  		if err := decodeJSON(&e, resp.Body); err != nil {
  			panic(err)
  		}
  	} else {
  		var lerr *legacyError
  		decodeJSON(&lerr, resp.Body)
  		if lerr != nil {
  			e.Errors = append(e.Errors, &ErrorObject{
  				Title:  lerr.Message,
  				Detail: lerr.Detail,
  			})
  		}
  	}
  
  	return &e
  }
docs: // NewHTTPError creates a new HTTP error from the given code.