From b35f11c270f83c383a6a682ddbbc9e32083f6423 Mon Sep 17 00:00:00 2001 From: Gulin7 Date: Wed, 27 Nov 2024 14:24:45 +0200 Subject: [PATCH] Move exceptions to errors.py --- scraper/src/mindtouch2zim/asset.py | 18 +++------- scraper/src/mindtouch2zim/client.py | 11 +----- scraper/src/mindtouch2zim/errors.py | 34 +++++++++++++++++++ .../src/mindtouch2zim/libretexts/glossary.py | 6 +--- scraper/src/mindtouch2zim/vimeo.py | 7 +--- 5 files changed, 42 insertions(+), 34 deletions(-) diff --git a/scraper/src/mindtouch2zim/asset.py b/scraper/src/mindtouch2zim/asset.py index 760aa9a..532c955 100644 --- a/scraper/src/mindtouch2zim/asset.py +++ b/scraper/src/mindtouch2zim/asset.py @@ -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 = { @@ -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 diff --git a/scraper/src/mindtouch2zim/client.py b/scraper/src/mindtouch2zim/client.py index 5e53c62..31bfb47 100644 --- a/scraper/src/mindtouch2zim/client.py +++ b/scraper/src/mindtouch2zim/client.py @@ -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] diff --git a/scraper/src/mindtouch2zim/errors.py b/scraper/src/mindtouch2zim/errors.py index 0d2a022..4a05de6 100644 --- a/scraper/src/mindtouch2zim/errors.py +++ b/scraper/src/mindtouch2zim/errors.py @@ -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 diff --git a/scraper/src/mindtouch2zim/libretexts/glossary.py b/scraper/src/mindtouch2zim/libretexts/glossary.py index fb772f3..f9ae4ea 100644 --- a/scraper/src/mindtouch2zim/libretexts/glossary.py +++ b/scraper/src/mindtouch2zim/libretexts/glossary.py @@ -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): diff --git a/scraper/src/mindtouch2zim/vimeo.py b/scraper/src/mindtouch2zim/vimeo.py index cacf477..b6348cd 100644 --- a/scraper/src/mindtouch2zim/vimeo.py +++ b/scraper/src/mindtouch2zim/vimeo.py @@ -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: