Skip to content

Commit ca07d23

Browse files
committed
Document ServerError might be raised in functions which might raise it
1 parent 2e12b7a commit ca07d23

File tree

4 files changed

+65
-8
lines changed

4 files changed

+65
-8
lines changed

src/vws/exceptions/custom_exceptions.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,25 @@ def response(self) -> Response:
6363
The response returned by Vuforia which included this error.
6464
"""
6565
return self._response
66+
67+
68+
class TooManyRequests(Exception): # pragma: no cover
69+
"""
70+
Exception raised when Vuforia returns a response with a result code
71+
'TooManyRequests'.
72+
"""
73+
74+
def __init__(self, response: Response) -> None:
75+
"""
76+
Args:
77+
response: The response returned by Vuforia.
78+
"""
79+
super().__init__(response.text)
80+
self._response = response
81+
82+
@property
83+
def response(self) -> Response:
84+
"""
85+
The response returned by Vuforia which included this error.
86+
"""
87+
return self._response

src/vws/exceptions/vws_exceptions.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,6 @@ class RequestQuotaReached(VWSException): # pragma: no cover
5656
"""
5757

5858

59-
class TooManyRequests(VWSException): # pragma: no cover
60-
"""
61-
Exception raised when Vuforia returns a response with a result code
62-
'TooManyRequests'.
63-
"""
64-
65-
6659
class TargetStatusProcessing(VWSException):
6760
"""
6861
Exception raised when Vuforia returns a response with a result code

src/vws/query.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ def query(
9595
file in the grayscale or RGB color space.
9696
~vws.exceptions.custom_exceptions.RequestEntityTooLarge: The given
9797
image is too large.
98+
~vws.exceptions.custom_exceptions.ServerError: There is an error
99+
with Vuforia's servers.
98100
99101
Returns:
100102
An ordered list of target details of matching targets.

src/vws/vws.py

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
OopsAnErrorOccurredPossiblyBadName,
2121
ServerError,
2222
TargetProcessingTimeout,
23+
TooManyRequests,
2324
)
2425
from vws.exceptions.vws_exceptions import (
2526
AuthenticationFailure,
@@ -37,7 +38,6 @@
3738
TargetQuotaReached,
3839
TargetStatusNotSuccess,
3940
TargetStatusProcessing,
40-
TooManyRequests,
4141
UnknownTarget,
4242
)
4343
from vws.reports import (
@@ -167,6 +167,10 @@ def _make_request(
167167
an HTML page with the text "Oops, an error occurred". This has
168168
been seen to happen when the given name includes a bad
169169
character.
170+
~vws.exceptions.custom_exceptions.ServerError: There is an error
171+
with Vuforia's servers.
172+
~vws.exceptions.custom_exceptions.TooManyRequests: Vuforia is rate
173+
limiting access.
170174
json.decoder.JSONDecodeError: The server did not respond with valid
171175
JSON. This may happen if the server address is not a valid
172176
Vuforia server.
@@ -274,6 +278,10 @@ def add_target(
274278
Vuforia returns an HTML page with the text "Oops, an error
275279
occurred". This has been seen to happen when the given name
276280
includes a bad character.
281+
~vws.exceptions.custom_exceptions.ServerError: There is an error
282+
with Vuforia's servers.
283+
~vws.exceptions.custom_exceptions.TooManyRequests: Vuforia is rate
284+
limiting access.
277285
"""
278286
image_data = _get_image_data(image=image)
279287
image_data_encoded = base64.b64encode(image_data).decode("ascii")
@@ -320,6 +328,10 @@ def get_target_record(self, target_id: str) -> TargetStatusAndRecord:
320328
does not match a target in the database.
321329
~vws.exceptions.vws_exceptions.RequestTimeTooSkewed: There is an
322330
error with the time sent to Vuforia.
331+
~vws.exceptions.custom_exceptions.ServerError: There is an error
332+
with Vuforia's servers.
333+
~vws.exceptions.custom_exceptions.TooManyRequests: Vuforia is rate
334+
limiting access.
323335
"""
324336
response = self._make_request(
325337
method="GET",
@@ -377,6 +389,10 @@ def wait_for_target_processed(
377389
does not match a target in the database.
378390
~vws.exceptions.vws_exceptions.RequestTimeTooSkewed: There is an
379391
error with the time sent to Vuforia.
392+
~vws.exceptions.custom_exceptions.ServerError: There is an error
393+
with Vuforia's servers.
394+
~vws.exceptions.custom_exceptions.TooManyRequests: Vuforia is rate
395+
limiting access.
380396
"""
381397
start_time = time.monotonic()
382398
while True:
@@ -408,6 +424,10 @@ def list_targets(self) -> list[str]:
408424
known database.
409425
~vws.exceptions.vws_exceptions.RequestTimeTooSkewed: There is an
410426
error with the time sent to Vuforia.
427+
~vws.exceptions.custom_exceptions.ServerError: There is an error
428+
with Vuforia's servers.
429+
~vws.exceptions.custom_exceptions.TooManyRequests: Vuforia is rate
430+
limiting access.
411431
"""
412432
response = self._make_request(
413433
method="GET",
@@ -441,6 +461,10 @@ def get_target_summary_report(self, target_id: str) -> TargetSummaryReport:
441461
does not match a target in the database.
442462
~vws.exceptions.vws_exceptions.RequestTimeTooSkewed: There is an
443463
error with the time sent to Vuforia.
464+
~vws.exceptions.custom_exceptions.ServerError: There is an error
465+
with Vuforia's servers.
466+
~vws.exceptions.custom_exceptions.TooManyRequests: Vuforia is rate
467+
limiting access.
444468
"""
445469
response = self._make_request(
446470
method="GET",
@@ -480,6 +504,10 @@ def get_database_summary_report(self) -> DatabaseSummaryReport:
480504
known database.
481505
~vws.exceptions.vws_exceptions.RequestTimeTooSkewed: There is an
482506
error with the time sent to Vuforia.
507+
~vws.exceptions.custom_exceptions.ServerError: There is an error
508+
with Vuforia's servers.
509+
~vws.exceptions.custom_exceptions.TooManyRequests: Vuforia is rate
510+
limiting access.
483511
"""
484512
response = self._make_request(
485513
method="GET",
@@ -526,6 +554,10 @@ def delete_target(self, target_id: str) -> None:
526554
target is in the processing state.
527555
~vws.exceptions.vws_exceptions.RequestTimeTooSkewed: There is an
528556
error with the time sent to Vuforia.
557+
~vws.exceptions.custom_exceptions.ServerError: There is an error
558+
with Vuforia's servers.
559+
~vws.exceptions.custom_exceptions.TooManyRequests: Vuforia is rate
560+
limiting access.
529561
"""
530562
self._make_request(
531563
method="DELETE",
@@ -559,6 +591,10 @@ def get_duplicate_targets(self, target_id: str) -> list[str]:
559591
inactive.
560592
~vws.exceptions.vws_exceptions.RequestTimeTooSkewed: There is an
561593
error with the time sent to Vuforia.
594+
~vws.exceptions.custom_exceptions.ServerError: There is an error
595+
with Vuforia's servers.
596+
~vws.exceptions.custom_exceptions.TooManyRequests: Vuforia is rate
597+
limiting access.
562598
"""
563599
response = self._make_request(
564600
method="GET",
@@ -618,6 +654,10 @@ def update_target(
618654
inactive.
619655
~vws.exceptions.vws_exceptions.RequestTimeTooSkewed: There is an
620656
error with the time sent to Vuforia.
657+
~vws.exceptions.custom_exceptions.ServerError: There is an error
658+
with Vuforia's servers.
659+
~vws.exceptions.custom_exceptions.TooManyRequests: Vuforia is rate
660+
limiting access.
621661
"""
622662
data: dict[str, str | bool | float | int] = {}
623663

0 commit comments

Comments
 (0)