I am using the Enterprise Tester API to import and update content on the web application. The program will work fine for a couple of hours but occasionally it runs into this unhandled exception:
An unhandled exception of type 'System.Net.Http.HttpRequestException' occurred in EnterpriseTester.API.Client.dll
Additional information: System.Net.Http.HttpRequestException status code does not indicate success: 500 (Internal Server Error)
At this point, Visual Studio breaks at the line where this exception occurs. However, when I click "Continue", the program will execute properly again.
From searching on the internet, it seems that I should use a try catch
block to handle the exception. I also want to be able to wait a little bit and execute the same line again to access the API.
try
{
client.UpdateScriptRun(Id,Run);
}
catch (HttpRequestException e)
{
Console.Writeline("HttpRequestException: {0}", e.Message);
Thread.Sleep(1000);
client.UpdateScriptRun(Id,Run);
}
I am not sure if something like this would solve the issue or if I need to look into a completely different solution.
It would be much appreciated if you could guide me to a solution that seems fit to this problem. Thank you!