Skip to content

Commit 2e3feb3

Browse files
Simplify client.go (#976)
Signed-off-by: Zhiwei Liang <zhiwei.liang@zliang.me>
1 parent 2cc0187 commit 2e3feb3

1 file changed

Lines changed: 2 additions & 11 deletions

File tree

client.go

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,6 @@ func NewClient(hc *http.Client) (client Client, err error) {
212212
SetRetryWaitTime(APISecondsPerPoll * time.Second).
213213
SetPollDelay(APISecondsPerPoll * time.Second).
214214
SetRetries().
215-
SetLogger(createLogger()).
216215
SetDebug(envDebug).
217216
enableLogSanitization()
218217

@@ -516,13 +515,7 @@ func (c *Client) doRequest(ctx context.Context, method, endpoint string, params
516515
)
517516

518517
for range c.retryCount {
519-
// Reset the body to the start for each retry if it's not nil
520-
if params.Body != nil {
521-
if _, seekErr := params.Body.Seek(0, io.SeekStart); seekErr != nil {
522-
return c.ErrorAndLogf("failed to seek to the start of the body: %v", seekErr.Error())
523-
}
524-
}
525-
518+
// createRequest seeks params.Body back to the start, so it's safe to retry.
526519
req, err = c.createRequest(ctx, method, endpoint, params)
527520
if err != nil {
528521
return err
@@ -784,9 +777,7 @@ func formatBody(body string) (string, error) {
784777
}
785778

786779
var jsonData any
787-
788-
err := json.Unmarshal([]byte(body), &jsonData)
789-
if err != nil {
780+
if err := json.Unmarshal([]byte(body), &jsonData); err != nil {
790781
return "", fmt.Errorf("error unmarshalling JSON: %w", err)
791782
}
792783

0 commit comments

Comments
 (0)