Skip to content

Commit d2f84ca

Browse files
committed
fix: fixing a failure in tests when there is a ratelimit in the public API, fixing some expects in tests, adding context managers in tests
1 parent 5f1751f commit d2f84ca

File tree

3 files changed

+155
-150
lines changed

3 files changed

+155
-150
lines changed

language_tool_python/server.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
parse_url, get_locale_language,
2424
get_language_tool_directory, get_server_cmd,
2525
FAILSAFE_LANGUAGE, startupinfo,
26-
LanguageToolError, ServerError, PathError,
26+
LanguageToolError, ServerError, PathError, RateLimitError,
2727
kill_process_force
2828
)
2929

@@ -485,6 +485,11 @@ def _query_server(
485485
)
486486
print(response)
487487
print(response.content)
488+
if response.status_code == 426:
489+
raise RateLimitError(
490+
'You have exceeded the rate limit for the free '
491+
'LanguageTool API. Please try again later.'
492+
)
488493
raise LanguageToolError(response.content.decode())
489494
except (IOError, http.client.HTTPException) as e:
490495
if self._remote is False:

language_tool_python/utils.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,15 @@ class PathError(LanguageToolError):
7373
pass
7474

7575

76+
class RateLimitError(LanguageToolError):
77+
"""
78+
Exception raised for errors related to rate limiting in the LanguageTool server.
79+
This exception is a subclass of `LanguageToolError` and is used to indicate
80+
issues such as exceeding the allowed number of requests to the public API without a key.
81+
"""
82+
pass
83+
84+
7685
def parse_url(url_str: str) -> str:
7786
"""
7887
Parse the given URL string and ensure it has a scheme.

0 commit comments

Comments
 (0)