summaryrefslogtreecommitdiffstats
path: root/src/lib/Proxy.py
diff options
context:
space:
mode:
authorChris St. Pierre <chris.a.st.pierre@gmail.com>2011-11-23 07:50:25 -0500
committerChris St. Pierre <chris.a.st.pierre@gmail.com>2011-11-23 07:50:25 -0500
commitc3f2470c4d6d9594764d2cd312f9733dbce77791 (patch)
tree695af19fd202b9d92a239fd670b6a5dbbf091e5c /src/lib/Proxy.py
parentabec6d84060655052345233a6e27a4379995b103 (diff)
downloadbcfg2-c3f2470c4d6d9594764d2cd312f9733dbce77791.tar.gz
bcfg2-c3f2470c4d6d9594764d2cd312f9733dbce77791.tar.bz2
bcfg2-c3f2470c4d6d9594764d2cd312f9733dbce77791.zip
made error handling from bcfg2 client more consistent; avoid some
backtraces
Diffstat (limited to 'src/lib/Proxy.py')
-rw-r--r--src/lib/Proxy.py39
1 files changed, 35 insertions, 4 deletions
diff --git a/src/lib/Proxy.py b/src/lib/Proxy.py
index b7801a03c..e1406bd99 100644
--- a/src/lib/Proxy.py
+++ b/src/lib/Proxy.py
@@ -44,6 +44,24 @@ __all__ = ["ComponentProxy",
"XMLRPCTransport"]
+class ProxyError(Exception):
+ """ ProxyError provides a consistent reporting interface to
+ the various xmlrpclib errors that might arise (mainly
+ ProtocolError and Fault) """
+ def __init__(self, err):
+ if isinstance(err, xmlrpclib.ProtocolError):
+ # cut out the password in the URL
+ url = re.sub(r'([^:]+):(.*?)@([^@]+:\d+/)', r'\1:******@\3',
+ err.url)
+ self.message = "XML-RPC Protocol Error for %s: %s (%s)" % \
+ (url, err.errmsg, err.errcode)
+ elif isinstance(err, xmlrpclib.Fault):
+ self.message = "XML-RPC Fault: %s (%s)" % (err.faultString,
+ err.faultCode)
+ else:
+ self.message = str(err)
+ self.args = (self.message, )
+
class CertificateError(Exception):
def __init__(self, commonName):
self.commonName = commonName
@@ -285,12 +303,25 @@ class XMLRPCTransport(xmlrpclib.Transport):
self.send_user_agent(h)
self.send_content(h, request_body)
- errcode, errmsg, headers = h.getreply()
+ if SSL_LIB == 'py26_ssl':
+ catch = ssl.SSLError
+ elif SSL_LIB == 'm2crypto':
+ catch = SSL.SSLError
+ try:
+ errcode, errmsg, headers = h.getreply()
+ except catch:
+ err = sys.exc_info()[1]
+ raise ProxyError(xmlrpclib.ProtocolError(host + handler,
+ 408,
+ str(err),
+ self._extra_headers))
+
if errcode != 200:
- # scrub password from the host
- hoststr = re.sub(r':[^@]+@', ':******@', host) + handler
- raise xmlrpclib.ProtocolError(hoststr, errcode, errmsg, headers)
+ raise ProxyError(xmlrpclib.ProtocolError(host + handler,
+ errcode,
+ errmsg,
+ headers))
self.verbose = verbose
msglen = int(headers.dict['content-length'])