all repos — homestead @ 980d1c718767b09292c6731eff111ba1edc3c53c

Code for my website

fix NPE in goatcounter request

Alan Pearce
commit

980d1c718767b09292c6731eff111ba1edc3c53c

parent

522324c7b7491a359d7a37931bfc2da402d014b0

1 file changed, 8 insertions(+), 5 deletions(-)

jump to
M internal/stats/goatcounter/count.gointernal/stats/goatcounter/count.go
@@ -104,20 +104,23 @@ req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "Bearer "+gc.token) go func(req *http.Request) { + var body []byte + res, err := gc.client.Do(req) if err != nil { gc.log.Warn("could not perform HTTP request", "error", err) } - defer res.Body.Close() + if res.Body != nil { + defer res.Body.Close() - body, err := io.ReadAll(res.Body) - if err != nil { - gc.log.Warn("could not read error body", "error", err) + body, err = io.ReadAll(res.Body) + if err != nil { + gc.log.Warn("could not read error body", "error", err) + } } if res.StatusCode != http.StatusAccepted { gc.log.Warn("failed to log pageview", "status", res.StatusCode, "body", body) } - }(req) return nil