mirror of https://github.com/vitalif/grive2
Fix #169
parent
98d5b92e5d
commit
93cae255fa
|
@ -81,6 +81,7 @@ long AuthAgent::Request(
|
||||||
{
|
{
|
||||||
long response;
|
long response;
|
||||||
Header auth;
|
Header auth;
|
||||||
|
m_interval = 0;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
auth = AppendHeader( hdr );
|
auth = AppendHeader( hdr );
|
||||||
|
@ -127,7 +128,17 @@ bool AuthAgent::CheckRetry( long response )
|
||||||
os::Sleep( 5 ) ;
|
os::Sleep( 5 ) ;
|
||||||
return true ;
|
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
|
// HTTP 401 Unauthorized. the auth token has been expired. refresh it
|
||||||
else if ( response == 401 )
|
else if ( response == 401 )
|
||||||
{
|
{
|
||||||
|
|
|
@ -71,6 +71,7 @@ private :
|
||||||
private :
|
private :
|
||||||
OAuth2& m_auth ;
|
OAuth2& m_auth ;
|
||||||
http::Agent* m_agent ;
|
http::Agent* m_agent ;
|
||||||
|
int m_interval ;
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
} // end of namespace
|
} // end of namespace
|
||||||
|
|
Loading…
Reference in New Issue