44 "bytes"
55 "context"
66 "encoding/json"
7+ "errors"
78 "fmt"
89 "io"
910 "net/http"
@@ -98,8 +99,9 @@ func genericRetry[T any](
9899 response , err := executeFunc (ctx , method , uri , queryParams , bodyParams , needsKeys , needsAuth )
99100 if err != nil {
100101 // Handle retryable errors
101- switch err .(type ) {
102- case * EncryptionError :
102+ var encErr * EncryptionError
103+ var tokenErr * TokenExpiredError
104+ if errors .As (err , & encErr ) {
103105 // Retrieve new encryption keys and retry
104106 if err := c .GetEncryptionKeys (ctx ); err != nil {
105107 return zero , fmt .Errorf ("failed to retrieve encryption keys: %w" , err )
@@ -110,7 +112,7 @@ func genericRetry[T any](
110112 return zero , err
111113 }
112114 return genericRetry (ctx , c , method , uri , queryParams , bodyParams , needsKeys , needsAuth , retryCount + 1 , executeFunc )
113- case * TokenExpiredError :
115+ } else if errors . As ( err , & tokenErr ) {
114116 // Login again and retry
115117 if err := c .Login (ctx ); err != nil {
116118 return zero , fmt .Errorf ("failed to login: %w" , err )
@@ -121,9 +123,8 @@ func genericRetry[T any](
121123 return zero , err
122124 }
123125 return genericRetry (ctx , c , method , uri , queryParams , bodyParams , needsKeys , needsAuth , retryCount + 1 , executeFunc )
124- default :
125- return zero , err
126126 }
127+ return zero , err
127128 }
128129
129130 return response , nil
@@ -260,11 +261,12 @@ func (c *Client) executeAPIRequest(ctx context.Context, method, uri string, quer
260261 }
261262
262263 // Calculate signature
263- if uri == EndpointCheckVersion {
264+ switch {
265+ case uri == EndpointCheckVersion :
264266 headers ["sign" ] = c .getSignFromTimestamp (timestamp )
265- } else if method == "GET" {
267+ case method == http . MethodGet :
266268 headers ["sign" ] = c .getSignFromPayloadAndTimestamp (originalQueryStr , timestamp )
267- } else if method == "POST" {
269+ case method == http . MethodPost :
268270 headers ["sign" ] = c .getSignFromPayloadAndTimestamp (originalBodyStr , timestamp )
269271 }
270272
0 commit comments