home-assistant-ecosystem / python-luftdaten

Python API for interacting with luftdaten.info
MIT License
5 stars 9 forks source link

Fix API connection error handling #13

Closed Cougar closed 1 year ago

Cougar commented 1 year ago

There are two httpx exceptions that needs to be catch. After this patch there will be no traceback prints in HomeAssistant log but just error messages. It doesn't make API more stable but makes log clean. I intentionally put different messages to the exception, however HA doesn't show these errors but just Unable to retrieve data from Sensor.Community

Fixes #12 Fixes home-assistant/core/issues/61687

tuxick commented 1 year ago

Maybe be more explicit about the exceptions, a connect timeout is not same as read timeout.

Cougar commented 1 year ago

Maybe be more explicit about the exceptions, a connect timeout is not same as read timeout.

You are right! I did change code in HA instance and later copy-paste it to the git but forgot to change the second exception text. This is now fixed

Cougar commented 1 year ago

I also fixed a test that did except httpx.ReadTimeout exception before.

I think it is a good idea to let this module raise only its own exceptions. As log as it is not needed to make a difference between connection and timeout errors, I think it is ok to use the same exception for both