]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
Provide more information with template URL error
authorJeff Peeler <jpeeler@redhat.com>
Mon, 19 Nov 2012 17:10:12 +0000 (12:10 -0500)
committerJeff Peeler <jpeeler@redhat.com>
Mon, 19 Nov 2012 19:00:28 +0000 (14:00 -0500)
Previously a generic read error was given. Inform the user with proper
exceptions for: the case when a resource is present but non-responsive
and when a resource is present but the requested data could not be
found.

Fixes bug 1072951

Change-Id: I35b92cea38358691015f8752e80efc6720e34e48
Signed-off-by: Jeff Peeler <jpeeler@redhat.com>
heat/api/cfn/v1/stacks.py

index 0be854ca48e136589c41e1736b50e2a2ae234f1e..552907b6d2813e1e3758d71ff22d034888f791a3 100644 (file)
@@ -21,6 +21,7 @@ import httplib
 import json
 import socket
 import urlparse
+import errno
 from heat.api.aws import exception
 from heat.api.aws import utils as api_utils
 from heat.common import wsgi
@@ -231,14 +232,26 @@ class StackController(object):
                 conn = httplib.HTTPSConnection(url.netloc)
             else:
                 conn = httplib.HTTPConnection(url.netloc)
-            conn.request("GET", url.path)
+
+            try:
+                conn.request("GET", url.path)
+            except Exception as e:
+                if e.errno == errno.ECONNREFUSED:
+                    msg = _('Connection refused to %s' % url.netloc)
+                    raise exception.HeatInvalidParameterValueError(detail=msg)
+                raise
+
             r1 = conn.getresponse()
             logger.info('status %d' % r1.status)
-            if r1.status == 200:
+            if r1.status == 200:  # OK
                 data = r1.read()
                 conn.close()
+            elif r1.status == 404:  # NOT_FOUND
+                msg = _('No match found for %s' % req.params['TemplateUrl'])
+                raise exception.HeatInvalidParameterValueError(detail=msg)
             else:
-                data = None
+                msg = _('Unexpected error, request returned %d' % r1.status)
+                raise exception.HeatInvalidParameterValueError(detail=msg)
             return data
 
         return None