From 6dd0738a8b6cdfe96009195ac007ffa169e9bf81 Mon Sep 17 00:00:00 2001 From: Madison May Date: Fri, 27 Feb 2015 16:12:16 -0500 Subject: [PATCH] Raise clear exception when a given private cloud does not support a given api --- indicoio/utils/__init__.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/indicoio/utils/__init__.py b/indicoio/utils/__init__.py index 85fb81d..d9ad14b 100644 --- a/indicoio/utils/__init__.py +++ b/indicoio/utils/__init__.py @@ -25,10 +25,14 @@ def api_handler(arg, cloud, api, batch=False, auth=None, **kwargs): if not auth: auth = config.AUTH - response = requests.post(url, data=json_data, headers=JSON_HEADERS, auth=auth).json() - results = response.get('results', False) + response = requests.post(url, data=json_data, headers=JSON_HEADERS, auth=auth) + if response.status_code == 503 and cloud != None: + raise Exception("Private cloud '%s' does not include api '%s'" % (cloud, api)) + + json_results = response.json() + results = json_results.get('results', False) if results is False: - error = response.get('error') + error = json_results.get('error') raise ValueError(error) return results