Skip to content

Commit efba4f9

Browse files
Merge pull request #2125 from VWS-Python/too-large-response
Include response in RequestEntityTooLarge exception
2 parents d3f4617 + c9aca9c commit efba4f9

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

src/vws/exceptions/custom_exceptions.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,21 @@ class RequestEntityTooLarge(Exception):
3737
Exception raised when the given image is too large.
3838
"""
3939

40+
def __init__(self, response: Response) -> None:
41+
"""
42+
Args:
43+
response: The response returned by Vuforia.
44+
"""
45+
super().__init__(response.text)
46+
self._response = response
47+
48+
@property
49+
def response(self) -> Response:
50+
"""
51+
The response returned by Vuforia which included this error.
52+
"""
53+
return self._response
54+
4055

4156
class TargetProcessingTimeout(Exception):
4257
"""

src/vws/query.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ def query(
152152
)
153153

154154
if response.status_code == HTTPStatus.REQUEST_ENTITY_TOO_LARGE:
155-
raise RequestEntityTooLarge
155+
raise RequestEntityTooLarge(response=response)
156156

157157
if "Integer out of range" in response.text:
158158
raise MaxNumResultsOutOfRange(response=response)

tests/test_cloud_reco_exceptions.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,13 @@ def test_image_too_large(
5858
A ``RequestEntityTooLarge`` exception is raised if an image which is too
5959
large is given.
6060
"""
61-
with pytest.raises(RequestEntityTooLarge):
61+
with pytest.raises(RequestEntityTooLarge) as exc:
6262
cloud_reco_client.query(image=png_too_large)
6363

64+
assert (
65+
exc.value.response.status_code == HTTPStatus.REQUEST_ENTITY_TOO_LARGE
66+
)
67+
6468

6569
def test_cloudrecoexception_inheritance() -> None:
6670
"""

0 commit comments

Comments
 (0)