Skip to content

Commit

Permalink
Fix Grive#169
Browse files Browse the repository at this point in the history
  • Loading branch information
vitalif committed Jul 28, 2018
1 parent 98d5b92 commit 93cae25
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
13 changes: 12 additions & 1 deletion libgrive/src/protocol/AuthAgent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ long AuthAgent::Request(
{
long response;
Header auth;
m_interval = 0;
do
{
auth = AppendHeader( hdr );
Expand Down Expand Up @@ -127,7 +128,17 @@ bool AuthAgent::CheckRetry( long response )
os::Sleep( 5 ) ;
return true ;
}

// HTTP 403 is the result of API rate limiting. attempt exponential backoff and try again
else if ( response == 429 || ( response == 403 && (
m_agent->LastError().find("\"reason\": \"userRateLimitExceeded\",") != std::string::npos ||
m_agent->LastError().find("\"reason\": \"rateLimitExceeded\",") != std::string::npos ) ) )
{
m_interval = m_interval <= 0 ? 1 : ( m_interval < 64 ? m_interval*2 : 120 );
Log( "request failed due to rate limiting: %1% (body: %2%). retrying in %3% seconds",
response, m_agent->LastError(), m_interval, log::warning ) ;
os::Sleep( m_interval ) ;
return true ;
}
// HTTP 401 Unauthorized. the auth token has been expired. refresh it
else if ( response == 401 )
{
Expand Down
1 change: 1 addition & 0 deletions libgrive/src/protocol/AuthAgent.hh
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ private :
private :
OAuth2& m_auth ;
http::Agent* m_agent ;
int m_interval ;
} ;

} // end of namespace

0 comments on commit 93cae25

Please sign in to comment.