From 3f2f069e1c22ee88afb67ef68164046222a009e3 Mon Sep 17 00:00:00 2001 From: Scott Hussey Date: Mon, 10 Jul 2017 20:39:07 -0500 Subject: [PATCH] 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 --- drydock_provisioner/error.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drydock_provisioner/error.py b/drydock_provisioner/error.py index f146787a..8f0076fd 100644 --- a/drydock_provisioner/error.py +++ b/drydock_provisioner/error.py @@ -44,9 +44,16 @@ class ApiError(Exception): self.status_code = code 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) class InvalidFormat(ApiError): def __init__(self, msg, code=400): 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 +