From 5ed59e1e3efb6227be6e23781ceba776a0c8d203 Mon Sep 17 00:00:00 2001
From: Michael Hanselmann <hansmi@google.com>
Date: Mon, 17 May 2010 13:49:41 +0200
Subject: [PATCH] RAPI client: Handle urllib2.HTTPError and raise
 GanetiApiError

This allows users of the RAPI client to catch GanetiApiError for all HTTP
errors.

Signed-off-by: Michael Hanselmann <hansmi@google.com>
Reviewed-by: Iustin Pop <iustin@google.com>
---
 lib/rapi/client.py | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/lib/rapi/client.py b/lib/rapi/client.py
index 298640e08..262e3893e 100644
--- a/lib/rapi/client.py
+++ b/lib/rapi/client.py
@@ -419,6 +419,8 @@ class GanetiRapiClient(object):
       encoded_response_content = resp.read()
     except (OpenSSL.SSL.Error, OpenSSL.crypto.Error), err:
       raise CertificateError("SSL issue: %s (%r)" % (err, err))
+    except urllib2.HTTPError, err:
+      raise GanetiApiError(str(err), code=err.code)
 
     if encoded_response_content:
       response_content = simplejson.loads(encoded_response_content)
-- 
GitLab