Skip to content

Commit

Permalink
fix: improve error handling in SpoolManCoordinator for API calls
Browse files Browse the repository at this point in the history
fixes #177
  • Loading branch information
Disane87 committed Jan 13, 2025
1 parent c36ce69 commit efeebea
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions custom_components/spoolman/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,12 @@ async def _async_update_data(self):
spools = await self.spoolman_api.get_spools(
{"allow_archived": show_archived}
)
except Exception as exception:
raise UpdateFailed(
f"Error fetching data from API: {exception}"
) from exception

try:
klipper_url = config.get(KLIPPER_URL, "")
if klipper_url is not None and klipper_url != "":
klipper_active_spool: int | None = await KlipperAPI(klipper_url).get_active_spool_id()
Expand All @@ -65,10 +70,8 @@ async def _async_update_data(self):
spool["klipper_active_spool"] = True
else:
spool["klipper_active_spool"] = False

return spools

except Exception as exception:
raise UpdateFailed(
f"Error fetching data from API: {exception}"
) from exception
_LOGGER.error(f"Error processing Klipper API data: {exception}")
# Continue returning spools even if Klipper processing fails

return spools

0 comments on commit efeebea

Please sign in to comment.