3

I'm having quite some trouble to handle the generic HttpRequestExeption which gets thrown by a standard HttpClient.

I think we all know this sort of code:

try {
   await client.GetAsync(url);
}
catch (HttpRequestException e)
{
   // do some nice error handling
}

My problem is that HttpRequestException wraps all kind of different connection exceptions. For example things like Host not found or SSL connection exception.

I now want to handle this exceptions differently for example by showing indivdual (and user friendly) error messages to be able not only to show the error but also to propose a solution for them to the user. But beside the fact, that the exception itself has an inner exception with a message, i see no type of identifier on the real connection problem.

I've found a bug report at the offical github repo (for a closely related problem) which supposed a dirty string match on the exception message https://github.com/dotnet/corefx/issues/24253#issuecomment-350865680 (which was rightly downvoted for that idea) but as far as i've tested it, some (but not all) of the exception messages gets translated to the current culture.

Has anyone encountered this problem before and has an idea?

  • https://stackoverflow.com/questions/22217619/how-do-i-get-statuscode-from-httprequestexception – Farhad Jabiyev Nov 23 '19 at 21:31
  • Well this is not exactly my problem. I can get the statuscode from the HttpRequestResponse but iam asking for the cases where you don't have a statuscode (oder an HttpRequestResponse object), because the request itself failed. – Dailydoseofweb Nov 24 '19 at 11:05

0 Answers0