From 6c7eec418a01bbad8d6fa99592d705d7f8d5da89 Mon Sep 17 00:00:00 2001 From: rare-magma Date: Sun, 19 Jan 2025 14:31:32 +0100 Subject: [PATCH] fix: add missing pointer check Signed-off-by: rare-magma --- main.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 28ae7af..ed9de0a 100644 --- a/main.go +++ b/main.go @@ -51,6 +51,9 @@ func shouldRetry(err error, resp *http.Response) bool { if err != nil { return true } + if resp == nil { + return true + } switch resp.StatusCode { case http.StatusInternalServerError, http.StatusBadGateway, http.StatusServiceUnavailable, http.StatusGatewayTimeout: return true @@ -77,7 +80,9 @@ func (t *retryableTransport) RoundTrip(req *http.Request) (*http.Response, error if req.Body != nil { req.Body = io.NopCloser(bytes.NewBuffer(bodyBytes)) } - log.Printf("Previous request failed with %s", resp.Status) + if resp != nil { + log.Printf("Previous request failed with %s", resp.Status) + } log.Printf("Retry %d of request to: %s", retries+1, req.URL) resp, err = t.transport.RoundTrip(req) retries++