diff options
Diffstat (limited to 'client/src')
-rw-r--r-- | client/src/leap/soledad/client/_blobs.py | 14 | ||||
-rw-r--r-- | client/src/leap/soledad/client/_http.py | 3 |
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( |