Skip to content
Merged
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
26 changes: 25 additions & 1 deletion boxsdk/exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,18 @@ class BoxAPIException(BoxException):
"""
Exception raised from the box session layer.
"""
def __init__(self, status, code=None, message=None, request_id=None, headers=None, url=None, method=None, context_info=None):
def __init__(
self,
status,
code=None,
message=None,
request_id=None,
headers=None,
url=None,
method=None,
context_info=None,
network_response=None,
):
"""
:param status:
HTTP status code of the failed response
Expand Down Expand Up @@ -59,6 +70,10 @@ def __init__(self, status, code=None, message=None, request_id=None, headers=Non
The context_info returned in the failed response.
:type context_info:
`dict`
:param network_response:
The failed response
:type network_response:
Requests `Response`
"""
super(BoxAPIException, self).__init__()
self._status = status
Expand All @@ -69,6 +84,7 @@ def __init__(self, status, code=None, message=None, request_id=None, headers=Non
self._url = url
self._method = method
self._context_info = context_info
self._network_response = network_response

def __unicode__(self):
return '\nMessage: {0}\nStatus: {1}\nCode: {2}\nRequest id: {3}\nHeaders: {4}\nURL: {5}\nMethod: {6}\nContext info: {7}'.format(
Expand Down Expand Up @@ -134,6 +150,14 @@ def context_info(self):
"""
return self._context_info

@property
def network_response(self):
"""
The response returned from the network.
:rtype: `NetworkResponse`
"""
return self._network_response


class BoxOAuthException(BoxException):
"""
Expand Down
8 changes: 8 additions & 0 deletions boxsdk/network/default_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,11 @@ def response_as_stream(self):
def access_token_used(self):
"""Base class override."""
return self._access_token_used

@property
def request_response(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Docstring. The one you used above would be fine.

"""
The response returned from the Requests library.
:rtype: `Response`
"""
return self._request_response
2 changes: 2 additions & 0 deletions boxsdk/session/box_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ def _raise_on_unsuccessful_request(self, network_response, expect_json_response,
url=url,
method=method,
context_info=response_json.get('context_info', None),
network_response=network_response
)
if expect_json_response and not self._is_json_response(network_response):
raise BoxAPIException(
Expand All @@ -256,6 +257,7 @@ def _raise_on_unsuccessful_request(self, network_response, expect_json_response,
message='Non-json response received, while expecting json response.',
url=url,
method=method,
network_response=network_response
)

def _prepare_and_send_request(
Expand Down