Skip to content

Commit 2e12b7a

Browse files
committed
Return a new error when the server returns a 5xx status code.
1 parent 693c3b0 commit 2e12b7a

File tree

4 files changed

+35
-0
lines changed

4 files changed

+35
-0
lines changed

CHANGELOG.rst

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

7+
* Return a new error (``vws.custom_exceptions.ServerError``) when the server returns a 5xx status code.
8+
79
2023.12.27
810
------------
911

src/vws/exceptions/custom_exceptions.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,24 @@ class TargetProcessingTimeout(Exception):
4242
"""
4343
Exception raised when waiting for a target to be processed times out.
4444
"""
45+
46+
47+
class ServerError(Exception): # pragma: no cover
48+
"""
49+
Exception raised when VWS returns a server error.
50+
"""
51+
52+
def __init__(self, response: Response) -> None:
53+
"""
54+
Args:
55+
response: The response returned by Vuforia.
56+
"""
57+
super().__init__(response.text)
58+
self._response = response
59+
60+
@property
61+
def response(self) -> Response:
62+
"""
63+
The response returned by Vuforia which included this error.
64+
"""
65+
return self._response

src/vws/query.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
)
2323
from vws.exceptions.custom_exceptions import (
2424
RequestEntityTooLarge,
25+
ServerError,
2526
)
2627
from vws.include_target_data import CloudRecoIncludeTargetData
2728
from vws.reports import QueryResult, TargetData
@@ -145,6 +146,11 @@ def query(
145146
if "Integer out of range" in response.text:
146147
raise MaxNumResultsOutOfRange(response=response)
147148

149+
if (
150+
response.status_code >= HTTPStatus.INTERNAL_SERVER_ERROR
151+
): # pragma: no cover
152+
raise ServerError(response=response)
153+
148154
result_code = response.json()["result_code"]
149155
if result_code != "Success":
150156
exception = {

src/vws/vws.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
from vws.exceptions.custom_exceptions import (
2020
OopsAnErrorOccurredPossiblyBadName,
21+
ServerError,
2122
TargetProcessingTimeout,
2223
)
2324
from vws.exceptions.vws_exceptions import (
@@ -188,6 +189,11 @@ def _make_request(
188189
# The Vuforia API returns a 429 response with no JSON body.
189190
raise TooManyRequests(response=response)
190191

192+
if (
193+
response.status_code >= HTTPStatus.INTERNAL_SERVER_ERROR
194+
): # pragma: no cover
195+
raise ServerError(response=response)
196+
191197
result_code = response.json()["result_code"]
192198

193199
if result_code == expected_result_code:

0 commit comments

Comments
 (0)