Skip to content

Commit ddd299d

Browse files
committed
add specific error type for rate limit
1 parent b6ab8a7 commit ddd299d

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

src/lpdb/session.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,17 @@ class LpdbError(Exception):
6565
pass
6666

6767

68+
class LpdbRateLimitError(LpdbError):
69+
"""
70+
Raised when the LPDB request created a fatal issue.
71+
"""
72+
73+
def __init__(self, wiki: str, table: str, *args):
74+
super().__init__(f'Rate limit reached for table "{table}" in "{wiki}"')
75+
self.wiki = wiki
76+
self.table = table
77+
78+
6879
class LpdbWarning(Warning):
6980
"""
7081
Warnings about LPDB response.
@@ -272,6 +283,14 @@ def _parse_results(response: LpdbResponse) -> list[dict[str, Any]]:
272283
lpdb_errors = response.get("error")
273284

274285
if lpdb_errors and len(lpdb_errors) != 0:
286+
rate_limit = re.match(
287+
r"API key \"[0-9A-Za-z]+\" limits for wiki \"(?P<wiki>[a-z]+)\" and table \"(?P<table>[a-z]+)\" exceeded\.",
288+
lpdb_errors[0],
289+
)
290+
if rate_limit:
291+
raise LpdbRateLimitError(
292+
wiki=rate_limit.group("wiki"), table=rate_limit.group("table")
293+
)
275294
raise LpdbError(re.sub(r"^Error: ?", "", lpdb_errors[0]))
276295
if lpdb_warnings and len(lpdb_warnings) != 0:
277296
for lpdb_warning in lpdb_warnings:

0 commit comments

Comments
 (0)