Commit 318d29b1 authored by Ilias Tsitsimpis's avatar Ilias Tsitsimpis

astakosclient: ReRaise json Exceptions as AstakosClient ones

parent 5299cc4d
...@@ -41,7 +41,7 @@ import simplejson ...@@ -41,7 +41,7 @@ import simplejson
from astakosclient.utils import retry, scheme_to_class from astakosclient.utils import retry, scheme_to_class
from astakosclient.errors import \ from astakosclient.errors import \
AstakosClientException, Unauthorized, BadRequest, NotFound, Forbidden, \ AstakosClientException, Unauthorized, BadRequest, NotFound, Forbidden, \
NoUserName, NoUUID, BadValue, QuotaLimit NoUserName, NoUUID, BadValue, QuotaLimit, InvalidResponse
# -------------------------------------------------------------------- # --------------------------------------------------------------------
...@@ -163,7 +163,14 @@ class AstakosClient(): ...@@ -163,7 +163,14 @@ class AstakosClient():
raise NotFound(message, data) raise NotFound(message, data)
elif status < 200 or status >= 300: elif status < 200 or status >= 300:
raise AstakosClientException(message, data, status) raise AstakosClientException(message, data, status)
return simplejson.loads(unicode(data))
try:
if data:
return simplejson.loads(unicode(data))
else:
return ""
except Exception as err:
raise InvalidResponse(str(err), data)
# ------------------------ # ------------------------
# GET /im/authenticate # GET /im/authenticate
......
...@@ -49,6 +49,12 @@ class BadValue(AstakosClientException): ...@@ -49,6 +49,12 @@ class BadValue(AstakosClientException):
super(BadValue, self).__init__(message, details) super(BadValue, self).__init__(message, details)
class InvalidResponse(AstakosClientException):
def __init__(self, message, details):
"""Return simplejson parse Exception as AstakosClient one"""
super(InvalidResponse, self).__init__(message, details)
class BadRequest(AstakosClientException): class BadRequest(AstakosClientException):
status = 400 status = 400
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment