Skip to content

Commit 037fea6

Browse files
committed
improve error message and close body earlier
1 parent 541c559 commit 037fea6

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

exporter/http.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,16 +96,14 @@ func getResponse(url string, token string, ch chan<- *Response) error {
9696
log.Infof("Fetching %s \n", url)
9797

9898
resp, err := getHTTPResponse(url, token) // do this earlier
99-
10099
if err != nil {
101-
return fmt.Errorf("Error converting body to byte array: %v", err)
100+
return fmt.Errorf("Error fetching http response: %v", err)
102101
}
102+
defer resp.Body.Close()
103+
103104

104105
// Read the body to a byte array so it can be used elsewhere
105106
body, err := ioutil.ReadAll(resp.Body)
106-
107-
defer resp.Body.Close()
108-
109107
if err != nil {
110108
return fmt.Errorf("Error converting body to byte array: %v", err)
111109
}

0 commit comments

Comments
 (0)