Skip to content

Commit a257568

Browse files
committed
handle http error before closing the body
This should help with this: panic: runtime error: invalid memory address or nil pointer dereference See example in the http docs: https://golang.org/pkg/net/http/
1 parent 7ec4b4e commit a257568

1 file changed

Lines changed: 1 addition & 3 deletions

File tree

exporter/gather.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,10 @@ func getRates(baseURL string, token string) (*RateLimits, error) {
5656
url := fmt.Sprintf("%s%s", baseURL, rateEndPoint)
5757

5858
resp, err := getHTTPResponse(url, token)
59-
60-
defer resp.Body.Close()
61-
6259
if err != nil {
6360
return &RateLimits{}, err
6461
}
62+
defer resp.Body.Close()
6563

6664
// Triggers if rate-limiting isn't enabled on private Github Enterprise installations
6765
if resp.StatusCode == 404 {

0 commit comments

Comments
 (0)