pollEndpoint: improve error output
Henry committed
Mar 21, 2015 at 02:36 UTC
6350cff7c023018b8b4e7c0f6106fa1ef2a84139
1 file changed
+6
-5
thirdparty/pollEndpoint/main.go
+6
-5
@@ -4,6 +4,7 @@ package main
4
import (
5
"flag"
6
"fmt"
7
+ "io/ioutil"
8
"net/http"
9
"net/url"
10
"os"
@@ -79,15 +80,15 @@ func main() {
80
81
func checkOK(resp *http.Response, err error) error {
82
if err == nil { // request worked
82
- resp.Body.Close()
83
+ defer resp.Body.Close()
84
if resp.StatusCode == http.StatusOK {
85
return nil
86
}
86
- return fmt.Errorf("Response not OK. %d %s", resp.StatusCode, resp.Status)
87
- } else if urlErr, ok := err.(*url.Error); ok { // expected error from http.Get()
88
- if urlErr.Op != "Get" || urlErr.URL != *endpoint {
89
- return fmt.Errorf("wrong url or endpoint error from http.Get() %#v", urlErr)
87
+ body, err := ioutil.ReadAll(resp.Body)
88
+ if err != nil {
89
+ fmt.Fprintf(os.Stderr, "pollEndpoint: ioutil.ReadAll() Error: %s", err)
90
}
91
+ return fmt.Errorf("Response not OK. %d %s %q", resp.StatusCode, resp.Status, string(body))
92
}
93
return err
94
}