Source File
errors.go
Belonging Package
github.com/goforj/httpx
package httpximport ()type HTTPError struct {StatusCode intStatus stringBody []byteHeader 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,}}
![]() |
The pages are generated with Golds v0.8.7. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |