Skip to content
This repository has been archived by the owner on Mar 18, 2019. It is now read-only.

FEATURE: Let requests raise http errors #172

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions coreapi/transports/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
3 changes: 3 additions & 0 deletions tests/test_transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down