mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-23 19:01:26 -07:00
[PR #6114/6cf67448 backport][stable-6] memset*.py: Fixed URLError handling (#6157)
memset*.py: Fixed URLError handling (#6114)
* memset.py: Added URLError exception and stderr to Response() object
* memset_*.py: Check response.status_code and response.stderr
* Added changelog fragment
* memset.py: Fixed pep8
* Renamed changelog fragment with .yml file extension
(cherry picked from commit 6cf674485f
)
Co-authored-by: Daniel Patrick <dani.p1991@gmail.com>
This commit is contained in:
parent
47514e1401
commit
36eff2fd99
8 changed files with 30 additions and 5 deletions
|
@ -26,6 +26,7 @@ class Response(object):
|
|||
def __init__(self):
|
||||
self.content = None
|
||||
self.status_code = None
|
||||
self.stderr = None
|
||||
|
||||
def json(self):
|
||||
return json.loads(self.content)
|
||||
|
@ -75,6 +76,10 @@ def memset_api_call(api_key, api_method, payload=None):
|
|||
msg = "Memset API returned a {0} response ({1}, {2})." . format(response.status_code, response.json()['error_type'], response.json()['error'])
|
||||
else:
|
||||
msg = "Memset API returned an error ({0}, {1})." . format(response.json()['error_type'], response.json()['error'])
|
||||
except urllib_error.URLError as e:
|
||||
has_failed = True
|
||||
msg = "An URLError occured ({0})." . format(type(e))
|
||||
response.stderr = "{0}" . format(e)
|
||||
|
||||
if msg is None:
|
||||
msg = response.json()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue