From 8909d28a6bd99bebca28d3346fea507e72f4ec47 Mon Sep 17 00:00:00 2001 From: Roland Date: Sun, 20 Oct 2024 15:37:24 -0600 Subject: [PATCH] Updating zim downloader with better error. --- modules/zim/downloader.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/modules/zim/downloader.py b/modules/zim/downloader.py index 7b906a8e..e2c6280c 100644 --- a/modules/zim/downloader.py +++ b/modules/zim/downloader.py @@ -15,16 +15,19 @@ logger = logger.getChild(__name__) async def fetch_hrefs(url: str) -> List[str]: - async with aiohttp_get(url, timeout=20) as response: - status = response.status - content = await response.content.read() - if status != HTTPStatus.OK: - raise RuntimeError(f'Failed to fetch file catalog') + try: + async with aiohttp_get(url, timeout=20) as response: + status = response.status + content = await response.content.read() + if status != HTTPStatus.OK: + raise RuntimeError(f'Failed to fetch Zim file catalog: {url}') + except TimeoutError: + raise TimeoutError(f'Timeout while fetching Zim file catalog: {url}') soup = get_html_soup(content) downloads = list() - for a_ in soup.find_all('a'): - downloads.append(a_['href']) + for a in soup.find_all('a'): + downloads.append(a['href']) return downloads