errors/http.go
func FromHTTP(resp *http.Response) Error {
	if resp.StatusCode < 399 {
		return nil
	}

	typ := HTTPStatusToType(resp.StatusCode)

	out := &impl{
		message: typ.String(),
		code:    parseCode(resp.Header.Get(CodeHeader)),
		typ:     typ,
	}

	// try to decode the error from the body
	defer resp.Body.Close()
	j := new(jsonError)
	err := json.NewDecoder(resp.Body).Decode(j)
	if err == nil {
		out.message = j.Message
		out.code = j.Code
		out.typ = j.Type
		out.attributes = j.Attributes
	}

	return out
}
func FromHTTP(resp *http.Response) Error {
	if resp.StatusCode < 399 {
		return nil
	}

	typ := HTTPStatusToType(resp.StatusCode)

	out := &impl{
		message: typ.String(),
		code:    parseCode(resp.Header.Get(CodeHeader)),
		typ:     typ,
	}

	// try to decode the error from the body
	defer resp.Body.Close()
	j := new(jsonError)
	err := json.NewDecoder(resp.Body).Decode(j)
	if err == nil {
		out.message = j.Message
		out.code = j.Code
		out.typ = j.Type
		out.attributes = j.Attributes
	}

	return out
}
// FromHTTP parses the http.Response and returns the corresponding
// If the response is not an error (eg. 200 OK), it returns nil