summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@xinu.at>2016-07-06 08:41:22 +0200
committerFlorian Pritz <bluewind@xinu.at>2016-07-06 08:41:22 +0200
commit61284c48b7f014d234dee0b98a0bc439e8f51d56 (patch)
tree54253649097456d6d44e6302eb9f0620ba23372f
parent6cbbeb30fa14dc3e13f1cd51a8066d574469207e (diff)
Pass error_id in APIException
Signed-off-by: Florian Pritz <bluewind@xinu.at>
-rwxr-xr-xfb.py14
1 files changed, 8 insertions, 6 deletions
diff --git a/fb.py b/fb.py
index 8cb90c7..48b34f4 100755
--- a/fb.py
+++ b/fb.py
@@ -74,7 +74,9 @@ def make_temp_directory():
shutil.rmtree(temp_dir)
class APIException(Exception):
- pass
+ def __init__(self, message, error_id):
+ super().__init__(message)
+ self.error_id = error_id
class CURLWrapper:
def __init__(self, config):
@@ -131,7 +133,7 @@ class CURLWrapper:
if filesize > self.config["warnsize"]:
self.getServerConfig()
if filesize > self.serverConfig["upload_max_size"]:
- raise APIException("File too big: %s" % (file.path))
+ raise APIException("File too big: %s" % (file.path), "client-internal/file-too-big")
if self.serverConfig is not None and (currentChunkSize + filesize > self.serverConfig["request_max_size"] \
or len(chunks[currentChunk]) >= self.serverConfig["max_files_per_request"]):
@@ -220,16 +222,16 @@ class CURLWrapper:
try:
result = json.loads(response)
except ValueError:
- raise APIException("Invalid response:\n%s" % response)
+ raise APIException("Invalid response:\n%s" % response, "client-internal/invalid-response")
if result["status"] == "error":
- raise APIException("Request failed: %s" % result["message"])
+ raise APIException("Request failed: %s" % result["message"], result['error_id'])
if result["status"] != "success":
- raise APIException("Request failed or invalid response")
+ raise APIException("Request failed or invalid response", "client-internal/invalid-response")
httpcode = self.curl.getinfo(pycurl.HTTP_CODE)
if httpcode != 200:
- raise APIException("Invalid HTTP response code: %s" % httpcode)
+ raise APIException("Invalid HTTP response code: %s" % httpcode, "client-internal/invalid-response")
return result["data"]