Skip to content

Commit

Permalink
Move exceptions to errors.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Gulin7 committed Nov 27, 2024
1 parent 5134301 commit b35f11c
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 34 deletions.
18 changes: 5 additions & 13 deletions scraper/src/mindtouch2zim/asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@
from zimscraperlib.zim import Creator

from mindtouch2zim.constants import KNOWN_BAD_ASSETS_REGEX, logger, web_session
from mindtouch2zim.errors import KnownBadAssetFailedError
from mindtouch2zim.errors import (
KnownBadAssetFailedError,
S3CacheError,
S3InvalidCredentialsError,
)
from mindtouch2zim.utils import backoff_hdlr

SUPPORTED_IMAGE_MIME_TYPES = {
Expand All @@ -37,18 +41,6 @@
WEBP_OPTIONS = WebpMedium().options


class S3InvalidCredentialsError(Exception):
"""Raised when S3 credentials are invalid"""

pass


class S3CacheError(Exception):
"""Raised when there is a problem with the S3 cache"""

pass


class HeaderData(NamedTuple):
ident: str # ~version~ of the URL data to use for comparisons
content_type: str | None
Expand Down
11 changes: 1 addition & 10 deletions scraper/src/mindtouch2zim/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,10 @@
logger,
web_session,
)
from mindtouch2zim.errors import APITokenRetrievalError, MindtouchParsingError
from mindtouch2zim.html import get_soup


class MindtouchParsingError(Exception):
pass


class APITokenRetrievalError(Exception):
"""Exception raised when failing to retrieve API token to query website API"""

pass


class MindtouchHome(BaseModel):
home_url: str
welcome_text_paragraphs: list[str]
Expand Down
34 changes: 34 additions & 0 deletions scraper/src/mindtouch2zim/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,37 @@ class KnownBadAssetFailedError(Exception):
"""An exception raised when an asset known to be failing, failed as expected"""

pass


class VimeoThumbnailError(Exception):
"""Error raised when there is a problem with a vimeo video"""

pass


class GlossaryRewriteError(Exception):
"""Exception indicating a problem during glossary rewrite"""

pass


class S3InvalidCredentialsError(Exception):
"""Raised when S3 credentials are invalid"""

pass


class S3CacheError(Exception):
"""Raised when there is a problem with the S3 cache"""

pass


class MindtouchParsingError(Exception):
pass


class APITokenRetrievalError(Exception):
"""Exception raised when failing to retrieve API token to query website API"""

pass
6 changes: 1 addition & 5 deletions scraper/src/mindtouch2zim/libretexts/glossary.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@
from jinja2 import Template
from pydantic import BaseModel


class GlossaryRewriteError(Exception):
"""Exception indicating a problem during glossary rewrite"""

pass
from mindtouch2zim.errors import GlossaryRewriteError


class GlossaryEntry(BaseModel):
Expand Down
7 changes: 1 addition & 6 deletions scraper/src/mindtouch2zim/vimeo.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,7 @@
logger,
web_session,
)


class VimeoThumbnailError(Exception):
"""Error raised when there is a problem with a vimeo video"""

pass
from mindtouch2zim.errors import VimeoThumbnailError


def get_vimeo_thumbnail_url(video_url: str) -> str:
Expand Down

0 comments on commit b35f11c

Please sign in to comment.