mirror of
https://github.com/sprockets/sprockets.mixins.http.git
synced 2024-11-15 03:00:29 +00:00
Changed the default value of self._simplify_error_response to match
past behavior. If you set self._simplify_error_response to False, error responses with a JSON body will be deserialized and returned in their entirety. If you do nothing, error responses will be reduced down to the error message, as they have been for years. That seems less disruptive.
This commit is contained in:
parent
d298c13fff
commit
631918f0a3
3 changed files with 22 additions and 12 deletions
16
README.rst
16
README.rst
|
@ -85,9 +85,19 @@ As with Tornado, to use the curl client which has numerous benefits:
|
|||
Error Response Body
|
||||
-------------------
|
||||
|
||||
For errors, the HTTPResponse object will include a complete body.
|
||||
To reduce error response bodies down to just the error message, users of this
|
||||
mixin can set ``self.simplify_error_response = True``.
|
||||
For errors, i.e. a response with HTTP status code in the 400 range...
|
||||
|
||||
The HTTPResponse object's body is reduced down to just the error message.
|
||||
That is this mixin's default behavior.
|
||||
|
||||
For a JSON response body with Problem Details (RFC 7807), you may want more
|
||||
than just the error message. To gain access to the complete, deserialized
|
||||
response body; a class that uses this mixin can set:
|
||||
|
||||
.. code:: python
|
||||
|
||||
``self.simplify_error_response = False``.
|
||||
|
||||
|
||||
Environment Variables
|
||||
---------------------
|
||||
|
|
|
@ -31,14 +31,14 @@ class HTTPResponse:
|
|||
|
||||
"""
|
||||
|
||||
def __init__(self, simplify_error_response=False):
|
||||
def __init__(self, simplify_error_response=True):
|
||||
self._exceptions = []
|
||||
self._finish = None
|
||||
self._json = transcoders.JSONTranscoder()
|
||||
self._msgpack = transcoders.MsgPackTranscoder()
|
||||
self._responses = []
|
||||
self._start = time.time()
|
||||
self._simplify_error_response = simplify_error_response or False
|
||||
self._simplify_error_response = simplify_error_response
|
||||
|
||||
def __len__(self):
|
||||
"""Return the length of the exception stack and response stack.
|
||||
|
@ -255,7 +255,7 @@ class HTTPClientMixin:
|
|||
super().__init__(*args, **kwargs)
|
||||
self.__hcm_json = transcoders.JSONTranscoder()
|
||||
self.__hcm_msgpack = transcoders.MsgPackTranscoder()
|
||||
self.simplify_error_response = False
|
||||
self.simplify_error_response = True
|
||||
|
||||
async def http_fetch(self, url,
|
||||
method='GET',
|
||||
|
|
12
tests.py
12
tests.py
|
@ -440,19 +440,19 @@ class MixinTestCase(testing.AsyncHTTPTestCase):
|
|||
self.assertFalse(response.ok)
|
||||
self.assertEqual(response.code, 400)
|
||||
self.assertEqual(response.attempts, 1)
|
||||
self.assertEqual(
|
||||
response.body,
|
||||
{'message': 'Test Error', 'type': 'Test Error', 'traceback': None})
|
||||
self.assertEqual(response.body, 'Test Error')
|
||||
|
||||
@testing.gen_test
|
||||
def test_simpler_error_response(self):
|
||||
self.mixin.simplify_error_response = True
|
||||
def test_fancier_error_response(self):
|
||||
self.mixin.simplify_error_response = False
|
||||
response = yield self.mixin.http_fetch(
|
||||
self.get_url('/error?status_code=400&message=Test%20Error'))
|
||||
self.assertFalse(response.ok)
|
||||
self.assertEqual(response.code, 400)
|
||||
self.assertEqual(response.attempts, 1)
|
||||
self.assertEqual(response.body, 'Test Error')
|
||||
self.assertEqual(
|
||||
response.body,
|
||||
{'message': 'Test Error', 'type': 'Test Error', 'traceback': None})
|
||||
|
||||
@testing.gen_test
|
||||
def test_error_retry(self):
|
||||
|
|
Loading…
Reference in a new issue