Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type HTTPError ¶
HTTPError represents a HTTP error document as a Go error and implements net.Error
Example ¶
l, err := net.Listen("tcp", "127.0.0.1:0") go (&http.Server{}).Serve(l) defer l.Close() // get returns an error for non-200 responses. get := func(url string) (*http.Response, error) { resp, err := http.Get(url) if err == nil && resp.StatusCode != http.StatusOK { err = New(resp) // closes original resp.Body } return resp, err } url := fmt.Sprintf("http://%s/404", l.Addr()) resp, err := get(url) for i := 0; i < 3; i++ { // retry after temporary network/http errors. if neterr, ok := err.(net.Error); ok && neterr.Temporary() { resp, err = get(url) } else { break } } if err != nil { fmt.Println(err) return } defer resp.Body.Close() // use response
Output: http error: 404 Not Found: 404 page not found
func New ¶
New wraps a Response in an HTTPError. The response's Body is replaced by a small buffer so reading and closing it is purely optional.
Click to show internal directories.
Click to hide internal directories.