summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorVictor Shyba <victor1984@riseup.net>2017-07-20 04:31:40 -0300
committerdrebs <drebs@leap.se>2017-07-21 10:58:48 -0300
commit961e43404e0d23674360860b04ba5480e752cc94 (patch)
tree575403ebb74f9823df925b1ef166a5d7ac4723c4 /src
parent76cbf4cbf0876e06d1d8e2839b63dffc13c271dd (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')
-rw-r--r--src/leap/soledad/client/_db/blobs.py18
-rw-r--r--src/leap/soledad/common/blobs/__init__.py19
-rw-r--r--src/leap/soledad/server/_blobs.py8
3 files changed, 30 insertions, 15 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):
diff --git a/src/leap/soledad/common/blobs/__init__.py b/src/leap/soledad/common/blobs/__init__.py
index 814829ab..34a04d3c 100644
--- a/src/leap/soledad/common/blobs/__init__.py
+++ b/src/leap/soledad/common/blobs/__init__.py
@@ -1,3 +1,22 @@
+# -*- coding: utf-8 -*-
+# __init__.py
+# Copyright (C) 2017 LEAP
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+"""
+Represents flags that can be used on blobs.
+"""
from collections import namedtuple
ACCEPTED_FLAGS = ['PENDING', 'PROCESSING', 'PROCESSED', 'FAILED']
Flags = namedtuple('Flags', ' '.join(ACCEPTED_FLAGS))(*ACCEPTED_FLAGS)
diff --git a/src/leap/soledad/server/_blobs.py b/src/leap/soledad/server/_blobs.py
index 85983bd1..6afd802c 100644
--- a/src/leap/soledad/server/_blobs.py
+++ b/src/leap/soledad/server/_blobs.py
@@ -76,10 +76,6 @@ class FilesystemBlobsBackend(object):
def get_flags(self, user, blob_id, request, namespace=''):
path = self._get_path(user, blob_id, namespace)
- try:
- mkdir_p(os.path.split(path)[0])
- except OSError:
- pass
if not os.path.isfile(path):
# 404 - Not Found
request.setResponseCode(404)
@@ -91,10 +87,6 @@ class FilesystemBlobsBackend(object):
def set_flags(self, user, blob_id, request, namespace=''):
path = self._get_path(user, blob_id, namespace)
- try:
- mkdir_p(os.path.split(path)[0])
- except OSError:
- pass
if not os.path.isfile(path):
# 404 - Not Found
request.setResponseCode(404)