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?