Check if response is not empty
diff --git a/_modules/gerrit.py b/_modules/gerrit.py
index 6de9f0e..6f20230 100644
--- a/_modules/gerrit.py
+++ b/_modules/gerrit.py
@@ -71,7 +71,7 @@
elif response == '':
value = False
else:
- raise AnsibleGerritError(
+ raise Exception(
"Unexpected response for %s: %s" % (path, response))
return value
@@ -85,7 +85,7 @@
try:
value = gerrit.get(path)
except Exception as e:
- if e.response.status_code == 404:
+ if e.response and e.response.status_code == 404:
logging.debug("Ignoring exception %s", e)
logging.debug("Got %s", e.response.__dict__)
value = None
@@ -240,7 +240,7 @@
gerrit.delete(membership_path)
changed = True
except Exception as e:
- if e.response.status_code == 404:
+ if e.response and e.response.status_code == 404:
# This is a kludge, it'd be better to work out in advance
# which groups the user is a member of only via membership
# in a different. That's not trivial though with the
@@ -320,7 +320,7 @@
try:
account_info = gerrit.get('/accounts/%s' % _quote(username))
except Exception as e:
- if e.response.status_code == 404:
+ if e.response and e.response.status_code == 404:
logging.info("Account %s not found, creating it.", username)
account_info = _create_account(gerrit, username)
change = True
@@ -388,7 +388,7 @@
try:
group_info = gerrit.get('/groups/%s' % _quote(name))
except Exception as e:
- if e.response.status_code == 404:
+ if e.response and e.response.status_code == 404:
logging.info("Group %s not found, creating it.", name)
group_info = _create_group(gerrit, name)
change = True