Skip to content

Commit 9eeb17b

Browse files
committed
fix: handling the correct error code in zip download to catch an inexistent version
1 parent ac724f2 commit 9eeb17b

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

language_tool_python/download_lt.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from .utils import (
1414
find_existing_language_tool_downloads,
1515
get_language_tool_download_path,
16+
PathError,
1617
LTP_JAR_DIR_PATH_ENV_VAR
1718
)
1819

@@ -125,13 +126,13 @@ def http_get(url: str, out_file: IO[bytes], proxies: Optional[Dict[str, str]] =
125126
:type out_file: IO[bytes]
126127
:param proxies: Optional dictionary of proxies to use for the request.
127128
:type proxies: Optional[Dict[str, str]]
128-
:raises Exception: If the file could not be found at the given URL (HTTP 403).
129+
:raises PathError: If the file could not be found at the given URL (HTTP 404).
129130
"""
130131
req = requests.get(url, stream=True, proxies=proxies)
131132
content_length = req.headers.get('Content-Length')
132133
total = int(content_length) if content_length is not None else None
133-
if req.status_code == 403: # Not found on AWS
134-
raise Exception(f'Could not find at URL {url}.')
134+
if req.status_code == 404:
135+
raise PathError(f'Could not find at URL {url}. The given version may not exist.')
135136
version = re.search(r'(\d+\.\d+)', url).group(1)
136137
progress = tqdm.tqdm(unit="B", unit_scale=True, total=total,
137138
desc=f'Downloading LanguageTool {version}')

language_tool_python/utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ class PathError(LanguageToolError):
6565
"""
6666
Exception raised for errors in the file path used in LanguageTool.
6767
This error is raised when there is an issue with the file path provided
68-
to LanguageTool, such as the LanguageTool JAR file not being found.
68+
to LanguageTool, such as the LanguageTool JAR file not being found,
69+
or a download path not being a valid available file path.
6970
"""
7071
pass
7172

0 commit comments

Comments
 (0)