Skip to content

Commit 0732c9e

Browse files
Merge pull request #1385 from VWS-Python/better-oops-handling
Add better handling for communications with servers which do not serve the Vuforia API
2 parents 3810485 + 8807f64 commit 0732c9e

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

CHANGELOG.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Next
1111

1212
* Breaking change: The ``vws.exceptions.cloud_reco_exceptions.MatchProcessing`` is now ``vws.exceptions.custom_exceptions.ActiveMatchingTargetsDeleteProcessing``.
1313
* Added new exception ``vws.exceptions.custom_exceptions.RequestEntityTooLarge``.
14+
* Add better exception handling when querying a server which does not serve the Vuforia API.
1415

1516
2020.09.07.0
1617
------------

spelling_private_dict.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ ConnectionErrorPossiblyImageTooLarge
44
DateRangeError
55
ImageTooLarge
66
InactiveProject
7+
JSONDecodeError
78
MatchProcessing
89
MaxNumResultsOutOfRange
910
MetadataTooLarge

src/vws/vws.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,9 @@ def _make_request(
156156
HTML page with the text "Oops, an error occurred". This has
157157
been seen to happen when the given name includes a bad
158158
character.
159+
json.decoder.JSONDecodeError: The server did not respond with valid
160+
JSON. This may happen if the server address is not a valid
161+
Vuforia server.
159162
"""
160163
response = _target_api_request(
161164
server_access_key=self._server_access_key,
@@ -166,11 +169,10 @@ def _make_request(
166169
base_vws_url=self._base_vws_url,
167170
)
168171

169-
try:
170-
result_code = response.json()['result_code']
171-
except json.decoder.JSONDecodeError as exc:
172-
assert 'Oops' in response.text, response.text
173-
raise UnknownVWSErrorPossiblyBadName() from exc
172+
if 'Oops, an error occurred' in response.text:
173+
raise UnknownVWSErrorPossiblyBadName
174+
175+
result_code = response.json()['result_code']
174176

175177
if result_code == expected_result_code:
176178
return response

0 commit comments

Comments
 (0)