@@ -467,8 +467,12 @@ UploadResult upload(int attempt) {
467467 client .log .print (VERBOSE , "Uploading batch %s." , batch .sequence ());
468468
469469 try {
470- Integer headerRetryCount = attempt <= 1 ? null : Integer .valueOf (attempt - 1 );
471- Call <UploadResponse > call = client .service .upload (headerRetryCount , client .uploadUrl , batch );
470+ Call <UploadResponse > call ;
471+ if (attempt <= 1 ) {
472+ call = client .service .upload (client .uploadUrl , batch );
473+ } else {
474+ call = client .service .uploadWithRetryCount (attempt - 1 , client .uploadUrl , batch );
475+ }
472476 Response <UploadResponse > response = call .execute ();
473477
474478 if (response .isSuccessful ()) {
@@ -484,17 +488,24 @@ UploadResult upload(int attempt) {
484488 }
485489
486490 int status = response .code ();
487- String retryAfterHeader = response .headers ().get ("Retry-After" );
488- Long retryAfterSeconds = parseRetryAfterSeconds (retryAfterHeader );
489491
490- if (retryAfterSeconds != null && isStatusRetryAfterEligible (status )) {
492+ if (isStatusRetryAfterEligible (status )) {
493+ String retryAfterHeader = response .headers ().get ("Retry-After" );
494+ Long retryAfterSeconds = parseRetryAfterSeconds (retryAfterHeader );
495+ if (retryAfterSeconds != null ) {
496+ client .log .print (
497+ DEBUG ,
498+ "Could not upload batch %s due to status %s with Retry-After %s seconds. Retrying after delay." ,
499+ batch .sequence (),
500+ status ,
501+ retryAfterSeconds );
502+ return new UploadResult (RetryStrategy .RETRY_AFTER , retryAfterSeconds );
503+ }
491504 client .log .print (
492505 DEBUG ,
493- "Could not upload batch %s due to status %s with Retry-After %s seconds. Retrying after delay ." ,
506+ "Status %s did not have a valid Retry-After header ." ,
494507 batch .sequence (),
495- status ,
496- retryAfterSeconds );
497- return new UploadResult (RetryStrategy .RETRY_AFTER , retryAfterSeconds );
508+ status );
498509 }
499510
500511 if (isStatusRetryWithBackoff (status )) {
0 commit comments