From 809b0172d8ef6d9c512fbfffbd61f0fe2889d1c6 Mon Sep 17 00:00:00 2001 From: Benjamin Pereto Date: Fri, 19 Oct 2018 17:00:38 +0200 Subject: [PATCH 1/2] FEATURE: let requests raise exception on bad status --- coreapi/transports/http.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/coreapi/transports/http.py b/coreapi/transports/http.py index 7338e61..9ab7b9d 100644 --- a/coreapi/transports/http.py +++ b/coreapi/transports/http.py @@ -296,12 +296,6 @@ def _decode_result(response, decoders, force_codec=False): # No content returned in response. result = None - # Coerce 4xx and 5xx codes into errors. - is_error = response.status_code >= 400 and response.status_code <= 599 - if is_error and not isinstance(result, Error): - default_title = '%d %s' % (response.status_code, response.reason) - result = _coerce_to_error(result, default_title=default_title) - return result @@ -378,6 +372,7 @@ def transition(self, link, decoders, params=None, link_ancestors=None, force_cod request = _build_http_request(session, url, method, headers, encoding, params) settings = session.merge_environment_settings(request.url, None, None, None, None) response = session.send(request, **settings) + response.raise_for_status() result = _decode_result(response, decoders, force_codec) if isinstance(result, Document) and link_ancestors: From 05a2b0f29ba50d8b4031aa2c35d3050e0ea0e051 Mon Sep 17 00:00:00 2001 From: Benjamin Pereto Date: Fri, 19 Oct 2018 17:01:26 +0200 Subject: [PATCH 2/2] FEATURE: extend MockResponse with `raise_for_status` --- tests/test_integration.py | 3 +++ tests/test_transport.py | 3 +++ 2 files changed, 6 insertions(+) diff --git a/tests/test_integration.py b/tests/test_integration.py index 0a2e602..31661f5 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -23,6 +23,9 @@ def __init__(self, content): self.url = 'http://example.org' self.status_code = 200 + def raise_for_status(self): + pass + # Basic integration tests. diff --git a/tests/test_transport.py b/tests/test_transport.py index eeeb17a..8038edb 100644 --- a/tests/test_transport.py +++ b/tests/test_transport.py @@ -26,6 +26,9 @@ def __init__(self, content): self.url = 'http://example.org' self.status_code = 200 + def raise_for_status(self): + pass + # Test transport errors.