I am new to restSharp and trying to execute an API test using asynchronous way, below code is running without any issue, can someone help me to update the code such a way that it can handle any error?
public void Test()
{
RestClient client = new RestClient("https://reqres.in/");
RestRequest request = new RestRequest("/api/users?page=2", Method.Get);
request.AddHeader("Accept", "application/json");
var results = getAsyncGetData<UserList>(client, request).GetAwaiter().GetResult();
Assert.AreEqual(results.Data.per_page,6);
}
private static async Task<RestResponse<T>> getAsyncGetData<T>(RestClient client,RestRequest request) where T : new()
{
RestResponse<T> response = await client.ExecuteAsync<T>(request);
return response;}