-
Notifications
You must be signed in to change notification settings - Fork 31
Error codes on NSX (e.g. 400, 500) should throw an exception instead of SystemExit #13
Comments
Hi, I'm a user of your nice library and I was just about to post the same problem.(with version 2.0.3) In my opinion, raise Error is one of nice option, but another solution is to simply return OrderedDict same as the success response in http_session.py . It can be achieved by just escaping line-109 with small fix in line-103 (by calling 'xml_to_dict(et.fromstring(response.content))' instead of 'pretty_xml(response.content)'). Then, user can handle http error by referring OrderedDict's 'status'. If you prefer, i can send pull request that modify error handling like above. |
Hi @Asayu123 .... sorry that I'm late replying. I was really busy traveling. and now I have a pile of things to work on. I like your idea! The only problem I see is the dependence on exiting for existing code (e.g. nsxansible, pynsxv, ...). |
Hi @yfauser , I am glad you are safe!
I think it's a great idea because it gives both compatibility and flexibility. I like it ! |
- Updated readme with the new fail_mode= parameter and version bump
- Packaged nsxramlclient version 2.0.4
Hi @Asayu123, I added the 'raise' and 'continue' option to nsxramlclient into the devel branch. You can look at the last 3 commits referencing this issue for details. Can you test in your environment, and see if the new code works for you and is according to your expectation? If it works for you I will merge the new Version into master. You can download the 2.0.4 tarbal from the /dist folder and install it using 'pip install nsxramlclient....tar.gz' Thanks! |
- Added __str__ of the NsxError exception, so that one can simply use 'print e'
- Added changed 2.0.4 tarball for externel testing
Hi @yfauser , I tested your commit and I found it works perfect for me ! I believe that both new option will make this library much easier to handle. |
Currently nsxramlclient wil use SystemExit if a non successful status code like 400 or 500 is received from NSX (actually everything that is not in 200, 201 or 204).
Instead of using SystemExit we should define an exception and pass the error received from NSX into the Exception.
In the mean time one can catch non successful exits by using the following try/except block:
try:
------
-----
except SystemExit as e:
-----
The text was updated successfully, but these errors were encountered: