@@ -227,10 +227,30 @@ public async Task MakeRequest(Batch batch)
227227 // Error code 429 indicates rate limited.
228228 // Retry uploading in these cases.
229229 Thread . Sleep ( _backo . AttemptTime ( ) ) ;
230+ if ( statusCode == 429 )
231+ {
232+ Logger . Info ( $ "Too many request at the moment CurrentAttempt:{ _backo . CurrentAttempt } Retrying to send request", new Dict
233+ {
234+ { "batch id" , batch . MessageId } ,
235+ { "statusCode" , statusCode } ,
236+ { "duration (ms)" , watch . ElapsedMilliseconds }
237+ } ) ;
238+ }
239+ else
240+ {
241+ Logger . Info ( $ "Internal Segment Server error CurrentAttempt:{ _backo . CurrentAttempt } Retrying to send request", new Dict
242+ {
243+ { "batch id" , batch . MessageId } ,
244+ { "statusCode" , statusCode } ,
245+ { "duration (ms)" , watch . ElapsedMilliseconds }
246+ } ) ;
247+ }
230248 continue ;
231249 }
232- else if ( statusCode >= 400 )
250+ else
233251 {
252+ //If status code is greater or equal than 400 but not 429 should indicate is client error.
253+ //All other types of HTTP Status code are not errors (Between 100 and 399)
234254 responseStr = String . Format ( "Status Code {0}. " , statusCode ) ;
235255 responseStr += ex . Message ;
236256 break ;
@@ -277,21 +297,39 @@ public async Task MakeRequest(Batch batch)
277297 // Error code 429 indicates rate limited.
278298 // Retry uploading in these cases.
279299 await _backo . AttemptAsync ( ) ;
300+ if ( statusCode == 429 )
301+ {
302+ Logger . Info ( $ "Too many request at the moment CurrentAttempt:{ _backo . CurrentAttempt } Retrying to send request", new Dict
303+ {
304+ { "batch id" , batch . MessageId } ,
305+ { "statusCode" , statusCode } ,
306+ { "duration (ms)" , watch . ElapsedMilliseconds }
307+ } ) ;
308+ }
309+ else
310+ {
311+ Logger . Info ( $ "Internal Segment Server error CurrentAttempt:{ _backo . CurrentAttempt } Retrying to send request", new Dict
312+ {
313+ { "batch id" , batch . MessageId } ,
314+ { "statusCode" , statusCode } ,
315+ { "duration (ms)" , watch . ElapsedMilliseconds }
316+ } ) ;
317+ }
280318 continue ;
281319 }
282- else if ( statusCode >= 400 )
320+ else
283321 {
284- responseStr = String . Format ( "Status Code {0}. " , response . StatusCode ) ;
285- responseStr += await response . Content . ReadAsStringAsync ( ) . ConfigureAwait ( false ) ;
286322 break ;
287323 }
288324 }
289325#endif
290326 }
291327
292- if ( _backo . HasReachedMax || statusCode != ( int ) HttpStatusCode . OK )
328+ var hasBackoReachedMax = _backo . HasReachedMax ;
329+ if ( hasBackoReachedMax || statusCode != ( int ) HttpStatusCode . OK )
293330 {
294- Fail ( batch , new APIException ( "Unexpected Status Code" , responseStr ) , watch . ElapsedMilliseconds ) ;
331+ var message = $ "Has Backoff reached max: { hasBackoReachedMax } with number of Attempts:{ _backo . CurrentAttempt } ,\n Status Code: { statusCode } \n , response message: { responseStr } ";
332+ Fail ( batch , new APIException ( statusCode . ToString ( ) , message ) , watch . ElapsedMilliseconds ) ;
295333 if ( _backo . HasReachedMax )
296334 {
297335 _backo . Reset ( ) ;
0 commit comments