[FEAT] Adding in handling for secondary rate limit exceptions (#2473)

This commit is contained in:
Chris Simpson
2022-07-11 15:03:31 +01:00
committed by GitHub
parent 6f78c521bc
commit b023602347
3 changed files with 95 additions and 1 deletions
+23 -1
View File
@@ -180,7 +180,7 @@ namespace Octokit.Tests.Http
}
[Fact]
public async Task ThrowsRateLimitExceededExceptionForForbidderResponse()
public async Task ThrowsRateLimitExceededExceptionForForbiddenResponse()
{
var httpClient = Substitute.For<IHttpClient>();
var response = CreateResponse(
@@ -202,6 +202,28 @@ namespace Octokit.Tests.Http
exception.Message);
}
[Fact]
public async Task ThrowsSecondaryRateLimitExceededExceptionForForbiddenResponse()
{
var httpClient = Substitute.For<IHttpClient>();
var response = CreateResponse(
HttpStatusCode.Forbidden,
"{\"message\":\"You have exceeded a secondary rate limit. Please wait a few minutes before you try again.\"}");
httpClient.Send(Args.Request, Args.CancellationToken).Returns(Task.FromResult(response));
var connection = new Connection(new ProductHeaderValue("OctokitTests"),
_exampleUri,
Substitute.For<ICredentialStore>(),
httpClient,
Substitute.For<IJsonSerializer>());
var exception = await Assert.ThrowsAsync<SecondaryRateLimitExceededException>(
() => connection.GetResponse<string>(new Uri("endpoint", UriKind.Relative)));
Assert.Equal("You have exceeded a secondary rate limit. Please wait a few minutes before you try again.",
exception.Message);
}
[Fact]
public async Task ThrowsLoginAttemptsExceededExceptionForForbiddenResponse()
{