From ad19d57a37a4143051cfc7ece88319ae41e573fe Mon Sep 17 00:00:00 2001 From: Lucidiot Date: Thu, 4 Apr 2019 10:12:38 +0200 Subject: [PATCH] Add __repr__ and __str__ on two exceptions --- apistar/exceptions.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/apistar/exceptions.py b/apistar/exceptions.py index 6516f8fd..eaa02d45 100644 --- a/apistar/exceptions.py +++ b/apistar/exceptions.py @@ -63,6 +63,17 @@ def __init__(self, title, status_code, content): self.status_code = status_code self.content = content + def __repr__(self): + return '%s(%s, status_code=%s, content=%s)' % ( + self.__class__.__name__, + repr(self.title), + repr(self.status_code), + repr(self.content), + ) + + def __str__(self): + return repr(self.content) + class ClientError(Exception): """ @@ -72,3 +83,14 @@ class ClientError(Exception): def __init__(self, messages): self.messages = messages super().__init__(messages) + + def __repr__(self): + return '%s(messages=%s)' % ( + self.__class__.__name__, + repr(self.messages), + ) + + def __str__(self): + if len(self.messages) == 1 and not self.messages[0].index: + return self.messages[0].text + return str(self.messages)