Skip to content

Commit 2ccf96b

Browse files
Merge pull request #2069 from VWS-Python/too-many-requests
Represent and handle 429 error
2 parents 123af6d + 200f9e6 commit 2ccf96b

File tree

4 files changed

+18
-1
lines changed

4 files changed

+18
-1
lines changed

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55
},
66
"editor.defaultFormatter": "charliermarsh.ruff",
77
"editor.formatOnSave": true
8-
}
8+
},
9+
"esbonio.sphinx.confDir": ""
910
}

spelling_private_dict.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ TargetProcessingTimeout
1919
TargetQuotaReached
2020
TargetStatusNotSuccess
2121
TargetStatusProcessing
22+
TooManyRequests
2223
Ubuntu
2324
UnknownTarget
2425
UnknownVWSErrorPossiblyBadName

src/vws/exceptions/vws_exceptions.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,13 @@ 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+
5966
class TargetStatusProcessing(VWSException):
6067
"""
6168
Exception raised when Vuforia returns a response with a result code

src/vws/vws.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import json
99
import time
1010
from datetime import date
11+
from http import HTTPStatus
1112
from typing import TYPE_CHECKING, BinaryIO
1213
from urllib.parse import urljoin
1314

@@ -35,6 +36,7 @@
3536
TargetQuotaReached,
3637
TargetStatusNotSuccess,
3738
TargetStatusProcessing,
39+
TooManyRequests,
3840
UnknownTarget,
3941
)
4042
from vws.reports import (
@@ -180,6 +182,12 @@ def _make_request(
180182
if "Oops, an error occurred" in response.text:
181183
raise UnknownVWSErrorPossiblyBadName
182184

185+
if (
186+
response.status_code == HTTPStatus.TOO_MANY_REQUESTS
187+
): # pragma: no cover
188+
# The Vuforia API returns a 429 response with no JSON body.
189+
raise TooManyRequests(response=response)
190+
183191
result_code = response.json()["result_code"]
184192

185193
if result_code == expected_result_code:

0 commit comments

Comments
 (0)