diff options
| -rw-r--r-- | CHANGES.txt | 4 | ||||
| -rw-r--r-- | pyramid/httpexceptions.py | 2 | ||||
| -rw-r--r-- | pyramid/tests/test_httpexceptions.py | 6 |
3 files changed, 11 insertions, 1 deletions
diff --git a/CHANGES.txt b/CHANGES.txt index 218fea289..59a733bcd 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -7,6 +7,10 @@ Features Bug Fixes --------- +- HTTPException's accepts a detail kwarg that may be used to pass additional + details to the exception. You may now pass objects so long as they have a + valid __str__ method. See https://github.com/Pylons/pyramid/pull/2951 + Deprecations ------------ diff --git a/pyramid/httpexceptions.py b/pyramid/httpexceptions.py index a22b088c6..1f3934fdc 100644 --- a/pyramid/httpexceptions.py +++ b/pyramid/httpexceptions.py @@ -238,7 +238,7 @@ ${body}''') del self.content_length def __str__(self): - return self.detail or self.explanation + return str(self.detail) if self.detail else self.explanation def _json_formatter(self, status, body, title, environ): return {'message': body, diff --git a/pyramid/tests/test_httpexceptions.py b/pyramid/tests/test_httpexceptions.py index 224fa4cf0..e2d463008 100644 --- a/pyramid/tests/test_httpexceptions.py +++ b/pyramid/tests/test_httpexceptions.py @@ -2,6 +2,7 @@ import unittest from pyramid.compat import ( bytes_, + string_types, text_, ) @@ -364,6 +365,11 @@ class TestHTTPException(unittest.TestCase): body = list(exc(environ, start_response))[0] self.assertEqual(body, b'200 OK\n\n/La Pe\xc3\xb1a') + def test_allow_detail_non_str(self): + exc = self._makeOne(detail={'error': 'This is a test'}) + self.assertIsInstance(exc.__str__(), string_types) + + class TestRenderAllExceptionsWithoutArguments(unittest.TestCase): def _doit(self, content_type): from pyramid.httpexceptions import status_map |
