Gitlab Community Edition Instance

Commit 6da709bb authored by Marcel Hellkamp's avatar Marcel Hellkamp
Browse files

Return ApiError from failed rest calls

parent e02fada2
......@@ -45,8 +45,8 @@ class CDStar:
if rs.ok or (_expect_status and rs.status_code in _expect_status):
return rs
# TODO: handle errors
raise Exception(rs.text)
# TODO: handle hard errors (JSONDecodeError)
raise ApiError(rs.json())
def begin(self, autocommit=False, readonly=False):
""" Start a new transaction and return self.
......@@ -201,6 +201,33 @@ class CDStar:
class ApiError(Exception):
def __init__(self, json):
self.json = json
def error(self):
return self.json['error']
def message(self):
return self.json['message']
def status(self):
return self.json['status']
def detail(self):
return self.json.get('detail') or {}
def __repr__(self):
return '{0.error}({0.status, msg="{0.message}")'.format(self)
def __str__(self):
return '{0.error}({0.status, msg="{0.message}")'.format(self)
def _fix_filename(name):
# silently strip leading slashes
name = name.lstrip("/")
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment