File tree Expand file tree Collapse file tree 4 files changed +35
-0
lines changed Expand file tree Collapse file tree 4 files changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,8 @@ Changelog
4
4
Next
5
5
----
6
6
7
+ * Return a new error (``vws.custom_exceptions.ServerError ``) when the server returns a 5xx status code.
8
+
7
9
2023.12.27
8
10
------------
9
11
Original file line number Diff line number Diff line change @@ -42,3 +42,24 @@ class TargetProcessingTimeout(Exception):
42
42
"""
43
43
Exception raised when waiting for a target to be processed times out.
44
44
"""
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
Original file line number Diff line number Diff line change 22
22
)
23
23
from vws .exceptions .custom_exceptions import (
24
24
RequestEntityTooLarge ,
25
+ ServerError ,
25
26
)
26
27
from vws .include_target_data import CloudRecoIncludeTargetData
27
28
from vws .reports import QueryResult , TargetData
@@ -145,6 +146,11 @@ def query(
145
146
if "Integer out of range" in response .text :
146
147
raise MaxNumResultsOutOfRange (response = response )
147
148
149
+ if (
150
+ response .status_code >= HTTPStatus .INTERNAL_SERVER_ERROR
151
+ ): # pragma: no cover
152
+ raise ServerError (response = response )
153
+
148
154
result_code = response .json ()["result_code" ]
149
155
if result_code != "Success" :
150
156
exception = {
Original file line number Diff line number Diff line change 18
18
19
19
from vws .exceptions .custom_exceptions import (
20
20
OopsAnErrorOccurredPossiblyBadName ,
21
+ ServerError ,
21
22
TargetProcessingTimeout ,
22
23
)
23
24
from vws .exceptions .vws_exceptions import (
@@ -188,6 +189,11 @@ def _make_request(
188
189
# The Vuforia API returns a 429 response with no JSON body.
189
190
raise TooManyRequests (response = response )
190
191
192
+ if (
193
+ response .status_code >= HTTPStatus .INTERNAL_SERVER_ERROR
194
+ ): # pragma: no cover
195
+ raise ServerError (response = response )
196
+
191
197
result_code = response .json ()["result_code" ]
192
198
193
199
if result_code == expected_result_code :
You can’t perform that action at this time.
0 commit comments