diff options
author | Victor Shyba <victor1984@riseup.net> | 2017-07-20 04:31:40 -0300 |
---|---|---|
committer | drebs <drebs@leap.se> | 2017-07-21 10:58:48 -0300 |
commit | 961e43404e0d23674360860b04ba5480e752cc94 (patch) | |
tree | 575403ebb74f9823df925b1ef166a5d7ac4723c4 /src/leap/soledad/client/_db | |
parent | 76cbf4cbf0876e06d1d8e2839b63dffc13c271dd (diff) |
[refactor] error handling and missing headers
Improves error handling, add missing header to __init__.py and remove
mkdirs from flags methods. This is a commit from code review on !117.
Diffstat (limited to 'src/leap/soledad/client/_db')
-rw-r--r-- | src/leap/soledad/client/_db/blobs.py | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/src/leap/soledad/client/_db/blobs.py b/src/leap/soledad/client/_db/blobs.py index dbaf00b1..148e1ff1 100644 --- a/src/leap/soledad/client/_db/blobs.py +++ b/src/leap/soledad/client/_db/blobs.py @@ -114,7 +114,7 @@ def check_http_status(code): elif code == 406: raise InvalidFlagsError() elif code != 200: - raise SoledadError("Server Error") + raise SoledadError("Server Error: %s" % code) class DecrypterBuffer(object): @@ -272,6 +272,11 @@ class BlobManager(object): flags = BytesIO(json.dumps(flags)) uri = urljoin(self.remote, self.user + "/" + blob_id) response = yield self._client.post(uri, data=flags, params=params) + if response.code == 404: + logger.error("Blob not found during set_flags: %s" % blob_id) + msg = "No blob found on server while trying to set flags: %s" + raise SoledadError(msg % (blob_id)) + check_http_status(response.code) @defer.inlineCallbacks @@ -290,12 +295,11 @@ class BlobManager(object): """ uri = urljoin(self.remote, self.user + "/" + blob_id) params.update({'only_flags': True}) - data = yield self._client.get(uri, params=params) - try: - data = yield data.json() - except: - data = [] - defer.returnValue(data) + response = yield self._client.get(uri, params=params) + if response.code == 404: + logger.warn("Blob not found in server: %s" % blob_id) + defer.returnValue(None) + defer.returnValue((yield response.json())) @defer.inlineCallbacks def get(self, blob_id): |