Open matejmosko opened 1 month ago
Hi @matejmosko Could you please share a snippet to reproduce this? I just tried recreating this and i was getting expected outcome in all of the cases.
{"code":"rest_post_invalid_page_number","message":"The page number requested is larger than the number of pages available.","data":{"status":400}}
Posts Count: {code: rest_post_invalid_page_number, message: The page number requested is larger than the number of pages available., data: {status: 400}}
Exited.
I am getting the error response and the script exits as expected.
Additionally, the status code is 400, this should not be mapped to a success response in any circumstances because it is fundamentally wrong. I can look into this further with few more inputs on how to reproduce this.
Other options include, updating the library to the latest version. Also, you can get the total page count on each request headers. There is a getter for the same:
final response = await client.posts.list(
ListPostRequest(
page: 999999,
order: Order.asc,
),
);
response.map<void>(
onSuccess: (success) {
final pagesCount = success.totalPagesCount;
},
onFailure: (error) {
print(error.error);
},
);
@matejmosko Hey, any update here?
I am a bit busy now. I will have a look at it in a week. I am sorry
Dňa po 26. 8. 2024, 16:50 Arun Prakash @.***> napísal(a):
@matejmosko https://github.com/matejmosko Hey, any update here?
— Reply to this email directly, view it on GitHub https://github.com/ArunPrakashG/wordpress_client/issues/76#issuecomment-2310404899, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAOA64YD7SMCWEXFHKJVNCDZTM6CHAVCNFSM6AAAAABNAP7SOOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGMJQGQYDIOBZHE . You are receiving this because you were mentioned.Message ID: @.***>
Hey @matejmosko, it's not totally fine. I was just checked in. have a great day.
When I call for json, I sometimes stumble on a problem when I get out of the pages range. I set page variable dynamically for paging capability in my app. However when I increment the page number for your requests to more than the maximum count, I end up with endless loading.
When the response is rest_post_invalid_page_number, wordpress_client accepts this as success and tries to map the values into a list of posts. This results in this exception:
and the future client.posts.list(request) gets no response therefore it endlessly waits for the answer (and my loading is spinning endlessly as well)
Is there a way to get the Failure answer for the future even if the rawResponse is successfuly obtained, but it's invalid?