michielpost / Q42.HueApi

C# helper library to talk to the Philips Hue bridge
MIT License
411 stars 114 forks source link

Move try-catch-block into retry-loop in LocalHueApi #292

Closed ingmarvonfintel closed 1 year ago

ingmarvonfintel commented 1 year ago

If an exception occurs in the eventStreamReader, it is catched outside of the while-loop (retry-logic).

This happens often with my bridge due to some timeout. As the Exception is swallowed in an empty catchblock, i can not react to this in my application. If i move the try-catch-block into the while-loop, it works stable.

Message (TaskCanceledException): "The request was canceled due to the configured HttpClient.Timeout of 100 seconds elapsing."

Stacktrace: at System.Net.Http.HttpClient.HandleFailure(Exception e, Boolean telemetryStarted, HttpResponseMessage response, CancellationTokenSource cts, CancellationToken cancellationToken, CancellationTokenSource pendingRequestsCts) at System.Net.Http.HttpClient.d51.MoveNext() at HueApi.LocalHueApi.d7.MoveNext() in C:_DEV\Q42.HueApi\src\HueApi\LocalHueApi.cs:line 66

michielpost commented 1 year ago

Thanks for mentioning this. Originally this try/catch was included to automatically reconnect, because when testing the connection would close after each event. But it looks like the Hub has been updated and the connection now stays open. So I've completely removed the try/catch and you can now handle the exceptions in your own app.

Updated in version 0.9.6