Azure-Samples / service-fabric-dotnet-getting-started

Get started with Service Fabric with these simple introductory sample projects.
MIT License
230 stars 329 forks source link

Exception handling issues #38

Closed ishepherd closed 7 years ago

ishepherd commented 8 years ago

re WordCount.WebService.HttpExceptionHandler - Which version of which HttpClient are you using, that gives you HttpWebResponses and throws WebExceptions?

For example with a request of mine returning a 404 -

HttpClient.PostAsync returns me a Task<HttpResponseMessage> and nothing is thrown. I can access the Result, still nothing is thrown. I have to call EnsureSuccessStatusCode() on the result if I want something thrown, and this only ever throws HttpRequestException, which is not what your HttpExceptionHandler is looking for.

ishepherd commented 8 years ago

Not researched this (& noob) but my guess is, this was correct when HttpWebRequest was being used. This does throw WebExceptions but since @vturecek change (efb0c635f265591dc78875bea89bf26ca7600fac) the code is using HttpClient, I am finding it does not throw these exceptions

Unfortunately, I haven't tested the behavior in all these timeout/protocol/socket exception cases so I don't know the extent of changes needed to HttpExceptionHandler. Please advise...

vturecek commented 8 years ago

Looks like there's a line missing that checks for HttpRequestException. We're working on a better way to do this using HttpClientHandlers. We'll get this updated soon. In the meantime, take a look here to see how that works: https://github.com/xinyanmsft/SFStartupHttp/tree/master/src/Libs/Microsoft.ServiceFabric.Http/Client

ishepherd commented 8 years ago

Thanks for reply @vturecek

It takes more than a missing line to fix this example. As this HttpRequestException tells me basically nothing ... unless I want to string match on its (localized!) Message.

But thanks a lot for the full example to check out. I will come back to this next month.

vturecek commented 7 years ago

We've switched HTTP communication to use the SF reverse proxy, which we recommend over resolving service endpoints manually. We still have an example of that for reference though in our Service Fabric IoT sample