Create a error class for the API client
Use a custom exception class for the API client including the HTTP status code that API calls return
This commit is contained in:
parent
397e9e9769
commit
3f2f069e1c
@ -44,9 +44,16 @@ class ApiError(Exception):
|
|||||||
self.status_code = code
|
self.status_code = code
|
||||||
|
|
||||||
def to_json(self):
|
def to_json(self):
|
||||||
err_dict = {'error': msg, 'type': self.__class__.__name__}}
|
err_dict = {'error': msg, 'type': self.__class__.__name__}
|
||||||
return json.dumps(err_dict)
|
return json.dumps(err_dict)
|
||||||
|
|
||||||
class InvalidFormat(ApiError):
|
class InvalidFormat(ApiError):
|
||||||
def __init__(self, msg, code=400):
|
def __init__(self, msg, code=400):
|
||||||
super(InvalidFormat, self).__init__(msg, code=code)
|
super(InvalidFormat, self).__init__(msg, code=code)
|
||||||
|
|
||||||
|
class ClientError(Exception):
|
||||||
|
def __init__(self, msg, code=500):
|
||||||
|
super().__init__(msg)
|
||||||
|
self.message = msg
|
||||||
|
self.status_code = code
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user