lvermeulen / Bitbucket.Cloud.Net

C# client for Atlassian Bitbucket Cloud
MIT License
13 stars 19 forks source link

Wrong pagination #12

Closed alexeyvs closed 3 years ago

alexeyvs commented 4 years ago

Sometimes, getting error related to pagination

{
    "type": "error",
    "error": {
        "message": "Page is no longer valid"
    }
}

and stacktrace Flurl.Http.FlurlHttpException: Call failed with status code 400 (Bad Request): GET https://api.bitbucket.org/2.0/repositories/cloudpayments/cloudpayments.dashboard/pullrequests/32/activity?page=2 at at Flurl.Http.FlurlRequest.HandleExceptionAsync(HttpCall call, Exception ex, CancellationToken token) at at Flurl.Http.FlurlRequest.SendAsync(HttpMethod verb, HttpContent content, CancellationToken cancellationToken, HttpCompletionOption completionOption) at at Flurl.Http.FlurlRequest.SendAsync(HttpMethod verb, HttpContent content, CancellationToken cancellationToken, HttpCompletionOption completionOption) at at Flurl.Http.HttpResponseMessageExtensions.ReceiveJson[T](Task1 response) at Bitbucket.Cloud.Net.BitbucketCloudClient.<>c__DisplayClass228_0.<b__0>d.MoveNext() in C:\projects\Bitbucket.Cloud.Net\Bitbucket.Cloud.Net\src\Bitbucket.Cloud.Net\v2\Repositories\PullRequests\BitbucketCloudClient.cs:54 at Bitbucket.Cloud.Net.BitbucketCloudClient.GetPagedResultsAsync[T](Nullable1 maxPages, IDictionary2 queryParamValues, Func2 selector) in C:\projects\Bitbucket.Cloud.Net\Bitbucket.Cloud.Net\src\Bitbucket.Cloud.Net\BitbucketCloudClient.cs:98

The problem is with response and logic to check if next page exists isLastPage = selectorResults.Next == null

For url https://api.bitbucket.org/2.0/repositories/cloudpayments/cloudpayments.dashboard/pullrequests/32/activity?page=1 The response would be { "pagelen": 10, "values": [ ... ], "next": "https://api.bitbucket.org/2.0/repositories/cloudpayments/cloudpayments.dashboard/pullrequests/32/activity?ctx=M6CXugHbHz&page=1" }

while having only 10 results, the next field points to the same page 1, so we getting bad request