From a257568a94bc0f5a1fbe8ca750a917e524997923 Mon Sep 17 00:00:00 2001 From: Moritz Date: Wed, 2 Jan 2019 07:21:40 +0100 Subject: [PATCH] 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/ --- exporter/gather.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/exporter/gather.go b/exporter/gather.go index f9ec424a..14b6b7fb 100644 --- a/exporter/gather.go +++ b/exporter/gather.go @@ -56,12 +56,10 @@ func getRates(baseURL string, token string) (*RateLimits, error) { url := fmt.Sprintf("%s%s", baseURL, rateEndPoint) resp, err := getHTTPResponse(url, token) - - defer resp.Body.Close() - if err != nil { return &RateLimits{}, err } + defer resp.Body.Close() // Triggers if rate-limiting isn't enabled on private Github Enterprise installations if resp.StatusCode == 404 {