From e2dcc16c2c8dfc10bc4f970c6056b8152f21f107 Mon Sep 17 00:00:00 2001 From: Van Thong Nguyen Date: Fri, 17 May 2024 11:41:56 +0200 Subject: [PATCH] Fix unhandled error when preparing HTTP req (#235) * fix unhandled error when preparing HTTP req * ioutil.ReadAll is deprecated: As of Go 1.16, this function simply calls io.ReadAll --- request.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/request.go b/request.go index 72a66f6..b627810 100644 --- a/request.go +++ b/request.go @@ -6,7 +6,7 @@ import ( "encoding/json" "errors" "fmt" - "io/ioutil" + "io" "net" "net/http" "runtime" @@ -197,6 +197,9 @@ func (r *gsRequest) retryHTTPRequest(ctx context.Context, cfg *Config) (string, var responseBodyBytes []byte err := retryNTimes(func() (bool, error) { httpReq, err := r.prepareHTTPRequest(ctx, cfg) + if err != nil { + return false, err + } logger.Debugf("Request body: %v", httpReq.Body) logger.Debugf("Request headers: %v", maskHeaderCred(httpReq.Header)) resp, err := cfg.httpClient.Do(httpReq) @@ -221,7 +224,7 @@ func (r *gsRequest) retryHTTPRequest(ctx context.Context, cfg *Config) (string, statusCode := resp.StatusCode requestUUID = resp.Header.Get(requestUUIDHeader) - responseBodyBytes, err = ioutil.ReadAll(resp.Body) + responseBodyBytes, err = io.ReadAll(resp.Body) if err != nil { logger.Errorf("Error while reading the response's body: %v", err) return false, err