Closed mib1185 closed 1 year ago
A FritzSecurityError for an authorization error would be confusing. Also that the error message is html instead of plain text is a surprising result.
Beside this I want to keep the exception types as small as possible. Some background:
There are roughly two kinds of exceptions: the triple of FritzConnectionException
, FritzServiceError
, FritzActionError
and the group of all other exceptions. The latter gets used for errors reported from the router according to error codes defined by AVM and should not get interpreted or used otherwise.
The former are indicating that the user tries to call a service or an action not matching the known API or that something else has happened. This "something else" is covered by the generic FritzConnectionException
with a detailed message about the incident.
For example, if the device or network is unreachable or a timeout happened, the message starts with "Unable to get a connection" followed by more detailed information. Or in case of a permission issue the message starts with "Unable to perform operation" again followed by more information.
This way the error message provides all necessary information for applications to implement a specific error handling.
On the other hand, a FritzAuthorizationError
could be useful beside the generic FritzConnectionException
, to make it more clear for the user what happened – even if I don't want to introduce more exception types.
with your agreement, i would like to add the FritzAuthorizationError
(which raises i case of any "Unable to perform operation" case)
Please feel free to do it, but it should not cover any case. Just a html-response with a 401 status should raise this exception. So it could roughly be something like this:
STATUS_UNAUTHORIZED = 401
...
msg = f"Unable to perform operation. {detail}"
if response.status_code == STATUS_UNAUTHORIZED:
raise FritzAuthorizationError(msg)
raise FritzConnectionException(msg)
the FritzAuthorizationError
is added and tests were extended to check that only http/401 will raise it.
Further some small cleanup of unesed imports in soaper test module
Hi Klaus, can you consider to release a patch version to include this change ?
Thank you in advance,
Simone
Hi Simone, sorry for the delay. Patch version is difficult, because everything is merged to master. Something I should change. Hope to make a new release over the holidays.
Hi Klaus, can you be so kind are lease 1.10.4 ?
Simone
Hi Simone, unfortunately holiday season turns out to be busy season. Hope to care about the next release soon.
Hi Simone, took a long time, but got it -> 1.11.0
Actually, it is not differentiated between possible reasons for a connection issue (eq. unreachable or un-authorized). This causes issues in handling connection issues (see home-assistant/core/issues/71822)
With this a http-401 will raise a
FritzSecurityError
, which ensures that the we can distinguish between wrong credentials or just not reachable device.cc @chemelli74
prior this change
with this change