aboutsummaryrefslogtreecommitdiffstats
path: root/gsxws
diff options
context:
space:
mode:
authorFilipp Lepalaan <filipp@mac.com>2018-10-09 08:55:52 +0300
committerFilipp Lepalaan <filipp@mac.com>2018-10-09 08:55:52 +0300
commitd098a0f3097988758ef28ab48add4c5e262c8ec0 (patch)
tree303b06e51194a49760ff0964afde4f7b7d77ef43 /gsxws
parent5b0fd57edd30eb6e901289b56279489498ee6652 (diff)
downloadpy-gsxws-d098a0f3097988758ef28ab48add4c5e262c8ec0.tar.gz
py-gsxws-d098a0f3097988758ef28ab48add4c5e262c8ec0.tar.bz2
py-gsxws-d098a0f3097988758ef28ab48add4c5e262c8ec0.zip
Add custom exception type for connection errors
Diffstat (limited to 'gsxws')
-rw-r--r--gsxws/core.py16
1 files changed, 13 insertions, 3 deletions
diff --git a/gsxws/core.py b/gsxws/core.py
index 8910927..f9d6eb8 100644
--- a/gsxws/core.py
+++ b/gsxws/core.py
@@ -213,6 +213,13 @@ class GsxError(Exception):
return ' '.join(self.messages)
+class GsxConnectionError(GsxError):
+ """A more fatal-type HTTP error."""
+ def __init__(self, url, code, message):
+ self.messages = []
+ self.messages.append('%d: %s (%s)' % (code, message, url))
+
+
class GsxCache(object):
"""The cache creates a separate shelf for each GSX session."""
@@ -363,13 +370,16 @@ class GsxRequest(object):
else:
request.append(self.data)
- data = ET.tostring(self.env, "UTF-8")
+ data = ET.tostring(self.env, 'UTF-8')
res = self._send(method, data)
- xml = res.text.encode('utf-8')
+ xml = res.text.encode('utf8')
self.xml_response = xml
logging.debug("Response: %s %s %s" % (res.status_code, res.reason, xml))
+ if res.status_code > 400:
+ raise GsxConnectionError(self._url, res.status_code, res.reason)
+
if res.status_code > 200:
raise GsxError(xml=xml, url=self._url, status=res.status_code, message=res.reason)
@@ -384,7 +394,7 @@ class GsxRequest(object):
return ET.tostring(self.env)
def __str__(self):
- return str(self).encode('utf-8')
+ return str(self).encode('utf8')
class GsxResponse: