From ed4460990e9e71994c631dde545f50005b5ef769 Mon Sep 17 00:00:00 2001 From: Alexander Gordeev Date: Mon, 5 May 2014 15:49:03 +0400 Subject: Make encoding.serialize() more programmatical Introduce `serializable_fields` to express which class attributes to be serialized. Get rid of OrderedDict. Just replacing it with regular dict. Change-Id: I3f7639dab171d3d62e92d0d1bb6d7b071cf963ad --- ironic_python_agent/errors.py | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'ironic_python_agent/errors.py') diff --git a/ironic_python_agent/errors.py b/ironic_python_agent/errors.py index 151d8cea..0cb9ad4a 100644 --- a/ironic_python_agent/errors.py +++ b/ironic_python_agent/errors.py @@ -13,7 +13,6 @@ # limitations under the License. from ironic_python_agent import encoding -from ironic_python_agent import utils class RESTError(Exception, encoding.Serializable): @@ -21,15 +20,12 @@ class RESTError(Exception, encoding.Serializable): message = 'An error occurred' details = 'An unexpected error occurred. Please try back later.' status_code = 500 + serializable_fields = ('type', 'code', 'message', 'details') - def serialize(self): - """Turn a RESTError into a dict.""" - return utils.get_ordereddict([ - ('type', self.__class__.__name__), - ('code', self.status_code), - ('message', self.message), - ('details', self.details), - ]) + def __init__(self, *args, **kwargs): + super(RESTError, self).__init__(*args, **kwargs) + self.type = self.__class__.__name__ + self.code = self.status_code class InvalidContentError(RESTError): -- cgit v1.2.1