package httpx

import (
	
	

	
)

type HTTPError struct {
	StatusCode int
	Status     string
	Body       []byte
	Header     http.Header
}

// Error returns a short, human-friendly summary of the HTTP error.
// @group Errors
//
// Example: check for HTTP errors
//
//	type User struct {
//		Name string `json:"name"`
//	}
//
//	c := httpx.New()
//	res := httpx.Get[User](c, "https://example.com/users/1")
//	var httpErr *httpx.HTTPError
//	if errors.As(res.Err, &httpErr) {
//		_ = httpErr.StatusCode
//	}
func ( *HTTPError) () string {
	return fmt.Sprintf("httpx: http %d %s", .StatusCode, .Status)
}

func newHTTPError( *req.Response) *HTTPError {
	if  == nil {
		return &HTTPError{StatusCode: 0, Status: "missing response"}
	}
	return &HTTPError{
		StatusCode: .StatusCode,
		Status:     .Status,
		Body:       .Bytes(),
		Header:     .Header,
	}
}