kbr / fritzconnection

Python-Tool to communicate with the AVM Fritz!Box by the TR-064 protocol and the AHA-HTTP-Interface
MIT License
303 stars 59 forks source link

FritzHosts - get_mesh_topology: catch exception when using repeater #107

Closed AaronDavidSchneider closed 2 years ago

AaronDavidSchneider commented 2 years ago

Repeaters do not have access to meshlist.lua. In the current implementation of fritzhosts we would therefore get a JSONDecodeError when using get_mesh_topology on a repeater.

This PR catches the 404 error and returns None.

kbr commented 2 years ago

Good idea, never thought about this usecase. But returning None in case of failure may result in problems for the caller expecting something but None. From my point of view it may be better to raise an error. As it is an error related to an action I suppose a FritzActionError may be appropriate. So the code can look something like this (untested):

with self.fc.session.get(url) as response:
    if not response.ok:
        message = "Device has no access to topology information."
        raise FritzActionError(message)
    return response.text if raw else response.json()

May be it could also be a good idea to include the response status in the error message. What do you think?

AaronDavidSchneider commented 2 years ago

I agree! Thanks for the review!