@@ -82,17 +82,9 @@ func (c *Client) DoMultiPartRequest(method, endpoint string, files map[string][]
8282 ctx , cancel := context .WithTimeout (context .Background (), c .config .CustomTimeout )
8383 defer cancel ()
8484
85- var body io.Reader
86- var contentType string
87-
88- // Create multipart body in a function to ensure it runs again on retry
89- createBody := func () error {
90- var err error
91- body , contentType , err = createStreamingMultipartRequestBody (files , formDataFields , fileContentTypes , formDataPartHeaders , log )
92- return err
93- }
94-
95- if err := createBody (); err != nil {
85+ // Create multipart body
86+ body , contentType , err := createStreamingMultipartRequestBody (files , formDataFields , fileContentTypes , formDataPartHeaders , log )
87+ if err != nil {
9688 log .Error ("Failed to create streaming multipart request body" , zap .Error (err ))
9789 return nil , err
9890 }
@@ -102,63 +94,28 @@ func (c *Client) DoMultiPartRequest(method, endpoint string, files map[string][]
10294 log .Error ("Failed to create HTTP request" , zap .Error (err ))
10395 return nil , err
10496 }
97+ req .Header .Set ("Content-Type" , contentType )
10598
10699 // TODO cookies
107100
108101 (* c .Integration ).PrepRequestParamsAndAuth (req )
109102
110- var resp * http.Response
111- var requestErr error
112-
113- // Retry logic
114- maxRetries := 3
115- for attempt := 1 ; attempt <= maxRetries ; attempt ++ {
116- startTime := time .Now ()
117-
118- // Create a new request for each retry
119- if attempt > 1 {
120- if err := createBody (); err != nil {
121- log .Error ("Failed to recreate streaming multipart request body" , zap .Error (err ))
122- return nil , err
123- }
124- req , err = http .NewRequestWithContext (ctx , method , url , body )
125- if err != nil {
126- log .Error ("Failed to create HTTP request on retry" , zap .Error (err ))
127- return nil , err
128- }
129- req .Header .Set ("Content-Type" , contentType )
130- }
131-
132- resp , requestErr = c .http .Do (req )
133- duration := time .Since (startTime )
134-
135- if requestErr != nil {
136- log .Error ("Failed to send request" , zap .String ("method" , method ), zap .String ("endpoint" , endpoint ), zap .Error (requestErr ))
137- if attempt < maxRetries {
138- log .Info ("Retrying request" , zap .Int ("attempt" , attempt ))
139- time .Sleep (2 * time .Second )
140- continue
141- }
142- return nil , requestErr
143- }
144-
145- log .Debug ("Request sent successfully" , zap .String ("method" , method ), zap .String ("endpoint" , endpoint ), zap .Int ("status_code" , resp .StatusCode ), zap .Duration ("duration" , duration ))
103+ startTime := time .Now ()
104+ resp , requestErr := c .http .Do (req )
105+ duration := time .Since (startTime )
146106
147- if resp .StatusCode >= 200 && resp .StatusCode < 300 {
148- return resp , response .HandleAPISuccessResponse (resp , out , log )
149- }
107+ if requestErr != nil {
108+ log .Error ("Failed to send request" , zap .String ("method" , method ), zap .String ("endpoint" , endpoint ), zap .Error (requestErr ))
109+ return nil , requestErr
110+ }
150111
151- // If status code indicates a server error, retry
152- if resp .StatusCode >= 500 && attempt < maxRetries {
153- log .Info ("Retrying request due to server error" , zap .Int ("status_code" , resp .StatusCode ), zap .Int ("attempt" , attempt ))
154- time .Sleep (2 * time .Second )
155- continue
156- }
112+ log .Debug ("Request sent successfully" , zap .String ("method" , method ), zap .String ("endpoint" , endpoint ), zap .Int ("status_code" , resp .StatusCode ), zap .Duration ("duration" , duration ))
157113
158- return resp , response .HandleAPIErrorResponse (resp , log )
114+ if resp .StatusCode >= 200 && resp .StatusCode < 300 {
115+ return resp , response .HandleAPISuccessResponse (resp , out , log )
159116 }
160117
161- return resp , requestErr
118+ return resp , response . HandleAPIErrorResponse ( resp , log )
162119}
163120
164121// createStreamingMultipartRequestBody creates a streaming multipart request body with the provided files and form fields.
0 commit comments