@@ -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,64 +94,29 @@ 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 // Set the Content-Type header
107100 req .Header .Set ("Content-Type" , contentType )
108101
109102 (* c .Integration ).PrepRequestParamsAndAuth (req )
110103
111- var resp * http.Response
112- var requestErr error
113-
114- // Retry logic
115- maxRetries := 3
116- for attempt := 1 ; attempt <= maxRetries ; attempt ++ {
117- startTime := time .Now ()
118-
119- // Create a new request for each retry
120- if attempt > 1 {
121- if err := createBody (); err != nil {
122- log .Error ("Failed to recreate streaming multipart request body" , zap .Error (err ))
123- return nil , err
124- }
125- req , err = http .NewRequestWithContext (ctx , method , url , body )
126- if err != nil {
127- log .Error ("Failed to create HTTP request on retry" , zap .Error (err ))
128- return nil , err
129- }
130- req .Header .Set ("Content-Type" , contentType )
131- }
132-
133- resp , requestErr = c .http .Do (req )
134- duration := time .Since (startTime )
135-
136- if requestErr != nil {
137- log .Error ("Failed to send request" , zap .String ("method" , method ), zap .String ("endpoint" , endpoint ), zap .Error (requestErr ))
138- if attempt < maxRetries {
139- log .Info ("Retrying request" , zap .Int ("attempt" , attempt ))
140- time .Sleep (2 * time .Second )
141- continue
142- }
143- return nil , requestErr
144- }
145-
146- log .Debug ("Request sent successfully" , zap .String ("method" , method ), zap .String ("endpoint" , endpoint ), zap .Int ("status_code" , resp .StatusCode ), zap .Duration ("duration" , duration ))
104+ startTime := time .Now ()
105+ resp , requestErr := c .http .Do (req )
106+ duration := time .Since (startTime )
147107
148- if resp .StatusCode >= 200 && resp .StatusCode < 300 {
149- return resp , response .HandleAPISuccessResponse (resp , out , log )
150- }
108+ if requestErr != nil {
109+ log .Error ("Failed to send request" , zap .String ("method" , method ), zap .String ("endpoint" , endpoint ), zap .Error (requestErr ))
110+ return nil , requestErr
111+ }
151112
152- // If status code indicates a server error, retry
153- if resp .StatusCode >= 500 && attempt < maxRetries {
154- log .Info ("Retrying request due to server error" , zap .Int ("status_code" , resp .StatusCode ), zap .Int ("attempt" , attempt ))
155- time .Sleep (2 * time .Second )
156- continue
157- }
113+ log .Debug ("Request sent successfully" , zap .String ("method" , method ), zap .String ("endpoint" , endpoint ), zap .Int ("status_code" , resp .StatusCode ), zap .Duration ("duration" , duration ))
158114
159- return resp , response .HandleAPIErrorResponse (resp , log )
115+ if resp .StatusCode >= 200 && resp .StatusCode < 300 {
116+ return resp , response .HandleAPISuccessResponse (resp , out , log )
160117 }
161118
162- return resp , requestErr
119+ return resp , response . HandleAPIErrorResponse ( resp , log )
163120}
164121
165122// createStreamingMultipartRequestBody creates a streaming multipart request body with the provided files and form fields.
0 commit comments