diff --git a/astakosclient/astakosclient/__init__.py b/astakosclient/astakosclient/__init__.py index f4e4f5ca85fb59258c180c3ed73349c7f49c7983..22e6f12ee4904acc13020a3d66fb837f511b4e63 100644 --- a/astakosclient/astakosclient/__init__.py +++ b/astakosclient/astakosclient/__init__.py @@ -41,7 +41,7 @@ import simplejson from astakosclient.utils import retry, scheme_to_class from astakosclient.errors import \ AstakosClientException, Unauthorized, BadRequest, NotFound, Forbidden, \ - NoUserName, NoUUID, BadValue, QuotaLimit + NoUserName, NoUUID, BadValue, QuotaLimit, InvalidResponse # -------------------------------------------------------------------- @@ -163,7 +163,14 @@ class AstakosClient(): raise NotFound(message, data) elif status < 200 or status >= 300: 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 diff --git a/astakosclient/astakosclient/errors.py b/astakosclient/astakosclient/errors.py index 79cd57c0c01ba69b8f4faca87eecfff6de71beae..bdac24b8b93e04b42553b861fea8554075d5027e 100644 --- a/astakosclient/astakosclient/errors.py +++ b/astakosclient/astakosclient/errors.py @@ -49,6 +49,12 @@ class BadValue(AstakosClientException): 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): status = 400