diff --git a/coolamqp/exceptions.py b/coolamqp/exceptions.py index f10736b0e1921dca2b40135fb96fa0899cac8786..be3bdedda8e39d40ec6ada06f5451bea82e5d1f8 100644 --- a/coolamqp/exceptions.py +++ b/coolamqp/exceptions.py @@ -1,6 +1,7 @@ # coding=UTF-8 from __future__ import absolute_import, division, print_function +import six from coolamqp.framing.definitions import HARD_ERRORS, SOFT_ERRORS, CONNECTION_FORCED, INVALID_PATH, FRAME_ERROR, \ SYNTAX_ERROR, COMMAND_INVALID, CHANNEL_ERROR, UNEXPECTED_FRAME, RESOURCE_ERROR, NOT_ALLOWED, NOT_IMPLEMENTED, \ INTERNAL_ERROR, CONTENT_TOO_LARGE, NO_CONSUMERS, ACCESS_REFUSED, NOT_FOUND, RESOURCE_LOCKED, PRECONDITION_FAILED @@ -26,6 +27,17 @@ class AMQPError(CoolAMQPError): """Does this error close the connection?""" return self.reply_code in HARD_ERRORS + def __str__(self): + return u'AMQP error %s: %s' % (self.reply_code, self.reply_text) + + def __repr__(self): + return u'AMQPError(%s, %s, %s, %s)' % ( + repr(self.reply_code), + repr(self.reply_text), + repr(self.class_id), + repr(self.method_id), + ) + def __init__(self, *args): """ diff --git a/tests/test_exceptions.py b/tests/test_exceptions.py new file mode 100644 index 0000000000000000000000000000000000000000..516ff965e963fb5e4feaf50475f7b0d2077122ea --- /dev/null +++ b/tests/test_exceptions.py @@ -0,0 +1,16 @@ +# coding=UTF-8 +from __future__ import print_function, absolute_import, division +import six +import unittest + +from coolamqp.exceptions import AMQPError + + +class TestExcs(unittest.TestCase): + def test_exist(self): + e = AMQPError(100, u'wtf', 0, 0) + + self.assertTrue(u'100' in str(e)) + self.assertTrue(u'wtf' in str(e)) + self.assertTrue(repr(e).startswith(u'AMQPError')) +