Skip to content

Commit cfc0636

Browse files
Merge pull request #2070 from VWS-Python/oops-error-occurred-rename
Rename UnknownVWSErrorPossiblyBadName and give it a response param/at…
2 parents 6b107fa + 6f40a40 commit cfc0636

File tree

5 files changed

+33
-10
lines changed

5 files changed

+33
-10
lines changed

CHANGELOG.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ Changelog
44
Next
55
----
66

7+
* Breaking change: The ``vws.exceptions.cloud_reco_exceptions.UnknownVWSErrorPossiblyBadName`` is now ``vws.exceptions.custom_exceptions.OopsAnErrorOccurredPossiblyBadName``.
8+
* ``vws.exceptions.custom_exceptions.OopsAnErrorOccurredPossiblyBadName`` now has a ``response`` parameter and attribute.
9+
710
2023.12.26
811
------------
912

spelling_private_dict.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ TargetStatusProcessing
2222
TooManyRequests
2323
Ubuntu
2424
UnknownTarget
25-
UnknownVWSErrorPossiblyBadName
25+
OopsAnErrorOccurredPossiblyBadName
2626
admin
2727
api
2828
args

src/vws/exceptions/custom_exceptions.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,32 @@
55
"""
66

77

8-
class UnknownVWSErrorPossiblyBadName(Exception):
8+
from requests import Response
9+
10+
11+
class OopsAnErrorOccurredPossiblyBadName(Exception):
912
"""
1013
Exception raised when VWS returns an HTML page which says "Oops, an error
1114
occurred".
1215
1316
This has been seen to happen when the given name includes a bad character.
1417
"""
1518

19+
def __init__(self, response: Response) -> None:
20+
"""
21+
Args:
22+
response: The response returned by Vuforia.
23+
"""
24+
super().__init__(response.text)
25+
self._response = response
26+
27+
@property
28+
def response(self) -> Response:
29+
"""
30+
The response returned by Vuforia which included this error.
31+
"""
32+
return self._response
33+
1634

1735
class RequestEntityTooLarge(Exception):
1836
"""

src/vws/vws.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
from vws_auth_tools import authorization_header, rfc_1123_date
1818

1919
from vws.exceptions.custom_exceptions import (
20+
OopsAnErrorOccurredPossiblyBadName,
2021
TargetProcessingTimeout,
21-
UnknownVWSErrorPossiblyBadName,
2222
)
2323
from vws.exceptions.vws_exceptions import (
2424
AuthenticationFailure,
@@ -162,8 +162,8 @@ def _make_request(
162162
The response to the request made by `requests`.
163163
164164
Raises:
165-
~vws.exceptions.UnknownVWSErrorPossiblyBadName: Vuforia returns an
166-
HTML page with the text "Oops, an error occurred". This has
165+
~vws.exceptions.OopsAnErrorOccurredPossiblyBadName: Vuforia returns
166+
an HTML page with the text "Oops, an error occurred". This has
167167
been seen to happen when the given name includes a bad
168168
character.
169169
json.decoder.JSONDecodeError: The server did not respond with valid
@@ -180,7 +180,7 @@ def _make_request(
180180
)
181181

182182
if "Oops, an error occurred" in response.text:
183-
raise UnknownVWSErrorPossiblyBadName
183+
raise OopsAnErrorOccurredPossiblyBadName(response=response)
184184

185185
if (
186186
response.status_code == HTTPStatus.TOO_MANY_REQUESTS
@@ -264,7 +264,7 @@ def add_target(
264264
inactive.
265265
~vws.exceptions.vws_exceptions.RequestTimeTooSkewed: There is an
266266
error with the time sent to Vuforia.
267-
~vws.exceptions.custom_exceptions.UnknownVWSErrorPossiblyBadName:
267+
~vws.exceptions.custom_exceptions.OopsAnErrorOccurredPossiblyBadName:
268268
Vuforia returns an HTML page with the text "Oops, an error
269269
occurred". This has been seen to happen when the given name
270270
includes a bad character.

tests/test_vws_exceptions.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from mock_vws.states import States
1414
from vws import VWS
1515
from vws.exceptions.base_exceptions import VWSException
16-
from vws.exceptions.custom_exceptions import UnknownVWSErrorPossiblyBadName
16+
from vws.exceptions.custom_exceptions import OopsAnErrorOccurredPossiblyBadName
1717
from vws.exceptions.vws_exceptions import (
1818
AuthenticationFailure,
1919
BadImage,
@@ -69,11 +69,11 @@ def test_invalid_given_id(vws_client: VWS) -> None:
6969
def test_add_bad_name(vws_client: VWS, high_quality_image: io.BytesIO) -> None:
7070
"""
7171
When a name with a bad character is given, an
72-
``UnknownVWSErrorPossiblyBadName`` exception is raised.
72+
``OopsAnErrorOccurredPossiblyBadName`` exception is raised.
7373
"""
7474
max_char_value = 65535
7575
bad_name = chr(max_char_value + 1)
76-
with pytest.raises(UnknownVWSErrorPossiblyBadName):
76+
with pytest.raises(OopsAnErrorOccurredPossiblyBadName) as exc:
7777
vws_client.add_target(
7878
name=bad_name,
7979
width=1,
@@ -82,6 +82,8 @@ def test_add_bad_name(vws_client: VWS, high_quality_image: io.BytesIO) -> None:
8282
application_metadata=None,
8383
)
8484

85+
assert exc.value.response.status_code == HTTPStatus.INTERNAL_SERVER_ERROR
86+
8587

8688
def test_request_quota_reached() -> None:
8789
"""

0 commit comments

Comments
 (0)