summaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
authorVictor Shyba <victor1984@riseup.net>2017-03-22 16:34:15 -0300
committerdrebs <drebs@leap.se>2017-04-04 18:27:38 +0200
commitaaa9115cfd4096a4fb6cf0ffbc2c07c75ed3a751 (patch)
tree4edc3cea4624b764a301ee482190c5dfe184eb7c /client
parent5acadaa7716a86448af02c3a078759ddddd45c85 (diff)
[feature] use 409 status code for existing blob id
Raising was generating 500, which is a generic status code for server side errors. This commit adds proper status code of 409 while handling the error on client side by translating the code into a proper exception class.
Diffstat (limited to 'client')
-rw-r--r--client/src/leap/soledad/client/_blobs.py14
-rw-r--r--client/src/leap/soledad/client/_http.py3
2 files changed, 14 insertions, 3 deletions
diff --git a/client/src/leap/soledad/client/_blobs.py b/client/src/leap/soledad/client/_blobs.py
index eb09d69f..0d25702c 100644
--- a/client/src/leap/soledad/client/_blobs.py
+++ b/client/src/leap/soledad/client/_blobs.py
@@ -36,6 +36,7 @@ import treq
from leap.soledad.client.sqlcipher import SQLCipherOptions
from leap.soledad.client import pragmas
+from leap.soledad.common.errors import SoledadError
from _crypto import DocInfo, BlobEncryptor, BlobDecryptor
from _http import HTTPClient
@@ -44,6 +45,10 @@ from _http import HTTPClient
logger = Logger()
+class BlobAlreadyExistsError(SoledadError):
+ pass
+
+
class ConnectionPool(adbapi.ConnectionPool):
def insertAndGetLastRowid(self, *args, **kwargs):
@@ -90,6 +95,13 @@ class ConnectionPool(adbapi.ConnectionPool):
return handle
+def check_http_status(code):
+ if code == 409:
+ raise BlobAlreadyExistsError()
+ elif code != 200:
+ raise SoledadError("Server Error")
+
+
class DecrypterBuffer(object):
def __init__(self, doc_id, rev, secret, tag):
@@ -217,7 +229,7 @@ class BlobManager(object):
armor=False)
fd = yield crypter.encrypt()
response = yield self._client.put(uri, data=fd)
- assert response.code == 200
+ check_http_status(response.code)
logger.info("Finished upload: %s" % (blob_id,))
@defer.inlineCallbacks
diff --git a/client/src/leap/soledad/client/_http.py b/client/src/leap/soledad/client/_http.py
index ba6f9a27..2a6b9e39 100644
--- a/client/src/leap/soledad/client/_http.py
+++ b/client/src/leap/soledad/client/_http.py
@@ -67,8 +67,7 @@ class PinnedTokenAgent(Agent):
def request(self, method, uri, headers=None, bodyProducer=None):
# authenticate the request
- if not headers:
- headers = Headers()
+ headers = headers or Headers()
headers.addRawHeader('Authorization', self._creds)
# perform the authenticated request
return Agent.request(