Skip to content

Commit

Permalink
Merge pull request #8 from diggyk/master
Browse files Browse the repository at this point in the history
More work on trapping request errors
  • Loading branch information
gmjosack committed Jun 16, 2015
2 parents 4aa9fda + 49acdb0 commit 2bf2f8c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
28 changes: 18 additions & 10 deletions bin/hermes
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ def request_get(path):
"""
response = requests.get(settings.hermes_server + path)

if response.status_code != requests.codes.ok:
if response.status_code != requests.codes.ok or not response.content:
try:
data = response.json()["error"]["message"]
except Exception:
data = "Received invalid response: {}".format(response)
data = "Received invalid response: {}".format(response.content)

raise HermesException(
"Error: {}".format(data)
)
raise HermesException(
"Error: {}".format(data)
)

return response

Expand All @@ -60,14 +60,17 @@ def request_post(path, json):
"""
response = requests.post(settings.hermes_server + path, json=json)

if response.status_code != requests.codes.created:
if (
response.status_code != requests.codes.created
or not response.content
):
try:
data = response.json()["error"]["message"]
except Exception:
data = "Received invalid response: {}".format(response)
raise HermesException(
"Error: {}".format(data)
)
data = "Received invalid response: {}".format(response.content)
raise HermesException(
"Error: {}".format(data)
)

return response

Expand Down Expand Up @@ -368,6 +371,11 @@ def list_host_labors_monitoring(args):
# an empty list because hermes doesn't know about this host and
# so we can assume it has no open labors
labors = []
else:
print "UNKNOWN: Querying Hermes returned an exception"
print ""
traceback.print_exc(file=sys.stdout)
sys.exit(3)
except Exception as exc:
print "UNKNOWN: Querying Hermes returned an exception"
print ""
Expand Down
2 changes: 1 addition & 1 deletion hermes/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.1.16"
__version__ = "0.1.18"

0 comments on commit 2bf2f8c

Please sign in to comment.