Skip to content

Commit 8c5e0ec

Browse files
authored
fix: Change exception type for missing location header (#871)
1 parent 8e0d640 commit 8c5e0ec

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

boxsdk/object/file.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import os
33
from datetime import datetime
44
from typing import TYPE_CHECKING, Optional, Tuple, Union, IO, Iterable, List, Any
5-
from boxsdk.exception import BoxException
5+
from boxsdk.exception import BoxAPIException
66

77
from boxsdk.util.datetime_formatter import normalize_date_to_rfc3339_format
88
from .item import Item
@@ -178,8 +178,16 @@ def get_download_url(self, file_version: Optional['FileVersion'] = None) -> str:
178178
expect_json_response=False,
179179
allow_redirects=False,
180180
)
181+
network_response = box_response.network_response
181182
if 'location' not in box_response.headers:
182-
raise BoxException('Download URL is not present in the response.')
183+
raise BoxAPIException(
184+
status=network_response.status_code,
185+
headers=network_response.headers,
186+
message='Download URL is not present in the response.',
187+
url=url,
188+
method='GET',
189+
network_response=network_response,
190+
)
183191

184192
return box_response.headers['location']
185193

test/unit/object/test_file.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from pytest_lazyfixture import lazy_fixture
99

1010
from boxsdk.config import API
11-
from boxsdk.exception import BoxAPIException, BoxException
11+
from boxsdk.exception import BoxAPIException
1212
from boxsdk.object.comment import Comment
1313
from boxsdk.object.file import File
1414
from boxsdk.object.file_version import FileVersion
@@ -240,9 +240,9 @@ def test_get_download_url(test_file, mock_box_session):
240240
def test_get_download_url_failed(test_file, mock_box_session):
241241
expected_url = f'{API.BASE_API_URL}/files/{test_file.object_id}/content'
242242
mock_box_session.get.return_value.headers = {}
243-
with pytest.raises(BoxException) as exc_info:
243+
with pytest.raises(BoxAPIException) as exc_info:
244244
test_file.get_download_url()
245-
assert exc_info.value.args[0] == 'Download URL is not present in the response.'
245+
assert exc_info.value.message == 'Download URL is not present in the response.'
246246
mock_box_session.get.assert_called_once_with(
247247
expected_url,
248248
params=None,

0 commit comments

Comments
 (0)