Skip to content

Commit

Permalink
raise error on non 200 response
Browse files Browse the repository at this point in the history
  • Loading branch information
Zehina committed Oct 20, 2024
1 parent b7e8098 commit 942e496
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
25 changes: 20 additions & 5 deletions webtoon_downloader/core/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@ class DownloadError(Exception):
def __str__(self) -> str:
if self.message:
return self.message
if self.cause:
return f'Failed to download from {self.url} caused by "{self.cause.__class__.__name__}"'
else:
return f'Failed to download from "{self.url}"'

return f"Failed to download from {self.url}"


@dataclass
Expand All @@ -44,9 +42,26 @@ class FetchError(Exception):
"""Exception raised due to a fetch error"""

series_url: str
message: str | None = None

def __str__(self) -> str:
if self.message:
return self.message
else:
return f"Failed to fetch from {self.series_url}"


@dataclass
class WebtoonFetchError(FetchError):
"""Exception raised due to a fetch error when retreiving Webtoon information"""

message: str | None = None

def __str__(self) -> str:
return f"Failed to fetch from {self.series_url}"
if self.message:
return self.message
else:
return f"Failed to fetch Webtoon information from {self.series_url}"


@dataclass
Expand Down
7 changes: 7 additions & 0 deletions webtoon_downloader/core/webtoon/fetchers.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
ChapterTitleFetchError,
ChapterURLFetchError,
SeriesTitleFetchError,
WebtoonFetchError,
)
from webtoon_downloader.core.webtoon import client
from webtoon_downloader.core.webtoon.models import ChapterInfo
Expand Down Expand Up @@ -111,6 +112,12 @@ async def get_chapters_details(
response = await self.client.get(
mobile_url, headers={**self.client.headers, "user-agent": client.get_mobile_ua()}
)
if response.status_code != 200:
raise WebtoonFetchError(
series_url,
f"Failed to fetch Webtoon information from {series_url}. Status code: {response.status_code}",
)

soup = BeautifulSoup(response.text, "html.parser")
chapter_items: Sequence[Tag] = soup.findAll("li", class_="_episodeItem")
series_title = self._get_series_title(soup)
Expand Down

0 comments on commit 942e496

Please sign in to comment.