Skip to content
This repository has been archived by the owner on Oct 16, 2019. It is now read-only.

Commit

Permalink
Merge pull request #30 from thlisym/fix/image-deletion-and-json-error
Browse files Browse the repository at this point in the history
Wraps any JSON error with our custom exception and fixes the delete i…
  • Loading branch information
thlisym authored Oct 21, 2018
2 parents 38be4fa + e7bef55 commit 2aebe0f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion hetznercloud/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def update(self, description=None, type=None):

def delete(self):
status_code, result = _get_results(self._config, "images/%s" % self.id, method="DELETE")
if status_code != 200:
if status_code != 204:
raise HetznerActionException(result)

@staticmethod
Expand Down
13 changes: 8 additions & 5 deletions hetznercloud/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@ def _get_results(config, endpoint, url_params=None, body=None, method="GET"):
if not request.text:
return request.status_code, ""

js = request.json()
if "action" in js and "error" in js["action"] and js["action"]["error"] is not None:
raise HetznerActionException(js["action"]["error"])

return request.status_code, js
try:
js = request.json()
if "action" in js and "error" in js["action"] and js["action"]["error"] is not None:
raise HetznerActionException(js["action"]["error"])

return request.status_code, js
except json.decoder.JSONDecodeError:
raise HetznerInternalServerErrorException("failed to deserialise JSON")

0 comments on commit 2aebe0f

Please sign in to comment.