Skip to content

Commit 768efc0

Browse files
kelseymorris95jmoldow
authored andcommitted
Extra exception info (#156)
Add `NetworkResponse` to `BoxAPIException`.
1 parent 6199de8 commit 768efc0

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

boxsdk/exception.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,18 @@ class BoxAPIException(BoxException):
2525
"""
2626
Exception raised from the box session layer.
2727
"""
28-
def __init__(self, status, code=None, message=None, request_id=None, headers=None, url=None, method=None, context_info=None):
28+
def __init__(
29+
self,
30+
status,
31+
code=None,
32+
message=None,
33+
request_id=None,
34+
headers=None,
35+
url=None,
36+
method=None,
37+
context_info=None,
38+
network_response=None,
39+
):
2940
"""
3041
:param status:
3142
HTTP status code of the failed response
@@ -59,6 +70,10 @@ def __init__(self, status, code=None, message=None, request_id=None, headers=Non
5970
The context_info returned in the failed response.
6071
:type context_info:
6172
`dict`
73+
:param network_response:
74+
The failed response
75+
:type network_response:
76+
Requests `Response`
6277
"""
6378
super(BoxAPIException, self).__init__()
6479
self._status = status
@@ -69,6 +84,7 @@ def __init__(self, status, code=None, message=None, request_id=None, headers=Non
6984
self._url = url
7085
self._method = method
7186
self._context_info = context_info
87+
self._network_response = network_response
7288

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

153+
@property
154+
def network_response(self):
155+
"""
156+
The response returned from the network.
157+
:rtype: `NetworkResponse`
158+
"""
159+
return self._network_response
160+
137161

138162
class BoxOAuthException(BoxException):
139163
"""

boxsdk/network/default_network.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,11 @@ def response_as_stream(self):
7171
def access_token_used(self):
7272
"""Base class override."""
7373
return self._access_token_used
74+
75+
@property
76+
def request_response(self):
77+
"""
78+
The response returned from the Requests library.
79+
:rtype: `Response`
80+
"""
81+
return self._request_response

boxsdk/session/box_session.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ def _raise_on_unsuccessful_request(self, network_response, expect_json_response,
248248
url=url,
249249
method=method,
250250
context_info=response_json.get('context_info', None),
251+
network_response=network_response
251252
)
252253
if expect_json_response and not self._is_json_response(network_response):
253254
raise BoxAPIException(
@@ -256,6 +257,7 @@ def _raise_on_unsuccessful_request(self, network_response, expect_json_response,
256257
message='Non-json response received, while expecting json response.',
257258
url=url,
258259
method=method,
260+
network_response=network_response
259261
)
260262

261263
def _prepare_and_send_request(

0 commit comments

Comments
 (0)