auto reset tokens on 429 part 2
This commit is contained in:
parent
219841e016
commit
425beb13ad
3 changed files with 17 additions and 9 deletions
|
@ -59,7 +59,10 @@ namespace BirdsiteLive.Twitter.Tools
|
||||||
_twitterClients.RemoveAt(i);
|
_twitterClients.RemoveAt(i);
|
||||||
_tokens.RemoveAt(i);
|
_tokens.RemoveAt(i);
|
||||||
}
|
}
|
||||||
catch (IndexOutOfRangeException _) {}
|
catch (IndexOutOfRangeException _)
|
||||||
|
{
|
||||||
|
_logger.LogError("Error refreshing twitter token");
|
||||||
|
}
|
||||||
|
|
||||||
await RefreshCred();
|
await RefreshCred();
|
||||||
}
|
}
|
||||||
|
|
|
@ -115,6 +115,7 @@ namespace BirdsiteLive.Twitter
|
||||||
}
|
}
|
||||||
catch (HttpRequestException e)
|
catch (HttpRequestException e)
|
||||||
{
|
{
|
||||||
|
_logger.LogError(e, "Error retrieving timeline of {Username}; refreshing client", username);
|
||||||
await _twitterAuthenticationInitializer.RefreshClient(request);
|
await _twitterAuthenticationInitializer.RefreshClient(request);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,18 +39,16 @@ namespace BirdsiteLive.Twitter
|
||||||
{
|
{
|
||||||
|
|
||||||
JsonDocument res;
|
JsonDocument res;
|
||||||
|
var client = await _twitterAuthenticationInitializer.MakeHttpClient();
|
||||||
|
using var request = _twitterAuthenticationInitializer.MakeHttpRequest(new HttpMethod("GET"), endpoint.Replace("elonmusk", username));
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
||||||
var client = await _twitterAuthenticationInitializer.MakeHttpClient();
|
var httpResponse = await client.SendAsync(request);
|
||||||
using (var request = _twitterAuthenticationInitializer.MakeHttpRequest(new HttpMethod("GET"), endpoint.Replace("elonmusk", username)))
|
httpResponse.EnsureSuccessStatusCode();
|
||||||
{
|
|
||||||
var httpResponse = await client.SendAsync(request);
|
|
||||||
httpResponse.EnsureSuccessStatusCode();
|
|
||||||
|
|
||||||
var c = await httpResponse.Content.ReadAsStringAsync();
|
var c = await httpResponse.Content.ReadAsStringAsync();
|
||||||
res = JsonDocument.Parse(c);
|
res = JsonDocument.Parse(c);
|
||||||
}
|
|
||||||
var result = res.RootElement.GetProperty("data").GetProperty("user").GetProperty("result");
|
var result = res.RootElement.GetProperty("data").GetProperty("user").GetProperty("result");
|
||||||
return Extract(result);
|
return Extract(result);
|
||||||
}
|
}
|
||||||
|
@ -70,6 +68,12 @@ namespace BirdsiteLive.Twitter
|
||||||
// throw;
|
// throw;
|
||||||
//}
|
//}
|
||||||
}
|
}
|
||||||
|
catch (HttpRequestException e)
|
||||||
|
{
|
||||||
|
_logger.LogError(e, "Error retrieving user {Username}, Refreshing client", username);
|
||||||
|
await _twitterAuthenticationInitializer.RefreshClient(request);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
_logger.LogError(e, "Error retrieving user {Username}", username);
|
_logger.LogError(e, "Error retrieving user {Username}", username);
|
||||||
|
|
Loading…
Add table
Reference in a new issue