Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide better error when pointed to something else than a Huawei LTE device #82

Open
scop opened this issue Sep 13, 2020 · 3 comments
Open
Labels
enhancement New feature or request

Comments

@scop
Copy link
Contributor

scop commented Sep 13, 2020

$ python x.py 
Traceback (most recent call last):
  File "x.py", line 8, in <module>
    connection = Connection('http://httpbin.org/')
  File "[...]/huawei_lte_api/Connection.py", line 45, in __init__
    self._initialize_csrf_tokens_and_session()
[...]
xml.parsers.expat.ExpatError: syntax error: line 1, column 54

Should provide a more indicative error than a generic XML parse one. Preferably something that the user code can examine to determine that the server is not a Huawei LTE device (e.g. somehow the 404 passed through). Perhaps should not try parsing XML for 404's, use requests' raise_for_error selectively (or everywhere except selectively not) etc.

@Salamek
Copy link
Owner

Salamek commented Oct 9, 2020

There is no 100% way to check if device we are trying to connect is a Huawei LTE modem (except checking MAC but that is BS)...
So i think best way will be to handle that XML parse exception and "rethrow" our own IDK something like:

raise ResponseParseException('Failed to parse XML response from device, are you sure that {host} is a supported Huawei LTE Modem?'.format(host=host))

@scop What do you think?

@scop
Copy link
Contributor Author

scop commented Oct 9, 2020

As mentioned, I think the HTTP status code should be a part of the exception thrown there, so users can use that in their decision making. Possibly also some other sanity checks on the structure we get if the XML parses successfully, if doable.

In case, let's chain the original exception if there is one, like raise OurException(..., htttp_status=...) from originalexception

@Salamek Salamek added the enhancement New feature or request label Nov 11, 2020
@Salamek
Copy link
Owner

Salamek commented Jan 6, 2022

Related #122

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants