private boolean checkRateExceededErrorAndUpdateWaitTime ( long clientCustomerId , Throwable throwable ) { if ( ReflectionUtil . isInstanceOf ( throwable , "ApiException" ) ) { try { Object [ ] errors = ( Object [ ] ) ReflectionUtil . invokeNoArgMethod ( throwable , "getErrors" ) ; if ( errors == null ) { return false ; } for ( Object error : errors ) { if ( ReflectionUtil . isInstanceOf ( error , "RateExceededError" ) ) { String rateScope = ( String ) ReflectionUtil . invokeNoArgMethod ( error , "getRateScope" ) ; Integer retryAfterSeconds = ( Integer ) ReflectionUtil . invokeNoArgMethod ( error , "getRetryAfterSeconds" ) ; logger . info ( "Encountered RateExceededError: scope={}, seconds={}." , rateScope , retryAfterSeconds ) ; if ( retryAfterSeconds == null ) { logger . warn ( "Unexpected rate exceeed error, missing retryAfterSeconds" ) ; } else if ( retryAfterSeconds != null ) { long waitForMillis = getWaitUntilMillis ( retryAfterSeconds . intValue ( ) ) ; if ( "DEVELOPER" . equals ( rateScope ) ) { updateTokenWaitTime ( waitForMillis ) ; return true ; } else if ( "ACCOUNT" . equals ( rateScope ) ) { updateAccountWaitTime ( clientCustomerId , waitForMillis ) ; return true ; } else { logger . warn ( "Unknown RateExceededError scope: " + rateScope , throwable ) ; } } } } } catch ( RateLimiterReflectionException e ) { // Failed during reflection analysis, just log and proceed. logger . error ( "Encountered error during analysis using reflection." , e ) ; } } return false ; }
Check whether the invocation causes RateExceededError and update wait time accordingly .