diff --git a/src/net/http/example_test.go b/src/net/http/example_test.go index c677d522385..2f411d1d2ec 100644 --- a/src/net/http/example_test.go +++ b/src/net/http/example_test.go @@ -45,12 +45,15 @@ func ExampleGet() { if err != nil { log.Fatal(err) } - robots, err := io.ReadAll(res.Body) + body, err := io.ReadAll(res.Body) res.Body.Close() + if res.StatusCode > 299 { + log.Fatalf("Response failed with status code: %d and\nbody: %s\n", res.StatusCode, body) + } if err != nil { log.Fatal(err) } - fmt.Printf("%s", robots) + fmt.Printf("%s", body) } func ExampleFileServer() {