Skip to content

Commit

Permalink
added requests params check
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonzorn committed Oct 19, 2024
1 parent ad163b2 commit b68c6da
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
4 changes: 4 additions & 0 deletions nlightreader/exceptions/parser_content_exc.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@ class NoContentError(Exception):

class FetchContentError(Exception):
pass


class RequestsParamsError(Exception):
pass
11 changes: 10 additions & 1 deletion nlightreader/parsers/hentai_manga/allhentai_hmanga.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from nlightreader.consts.urls import URL_ALLHENTAI, URL_ALLHENTAI_API
from nlightreader.consts.enums import Nl
from nlightreader.exceptions import parser_content_exc
from nlightreader.models import Chapter, Image, Manga
from nlightreader.parsers.catalogs_base import AbstractHentaiMangaCatalog
from nlightreader.utils.utils import get_html, make_request
Expand All @@ -18,7 +19,15 @@ def __init__(self):

def search_manga(self, form):
url = f"{self.url}/search"
params = {"q": form.search, "+": "Искать!", "fast-filter": "CREATION"}
if not form.search:
raise parser_content_exc.RequestsParamsError(
"Search field is empty",
)
params = {
"q": form.search,
"+": "Искать!",
"fast-filter": "CREATION",
}
response = make_request(
url,
"POST",
Expand Down
10 changes: 9 additions & 1 deletion nlightreader/parsers/hentai_manga/nhentai_hmanga.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from bs4 import BeautifulSoup, element

from nlightreader.consts.urls import URL_NHENTAI
from nlightreader.exceptions import parser_content_exc
from nlightreader.models import Chapter, Image, Manga
from nlightreader.parsers.catalogs_base import AbstractHentaiMangaCatalog
from nlightreader.utils.utils import get_html
Expand All @@ -17,7 +18,14 @@ def __init__(self):

def search_manga(self, form):
url = f"{self.url}/search"
params = {"page": form.page, "q": form.search}
if not form.search:
raise parser_content_exc.RequestsParamsError(
"Search field is empty",
)
params = {
"page": form.page,
"q": form.search,
}
response = get_html(
url,
headers=self.headers,
Expand Down
3 changes: 2 additions & 1 deletion nlightreader/widgets/NlightTemplates/BaseWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from nlightreader.exceptions.parser_content_exc import (
FetchContentError,
NoContentError,
RequestsParamsError,
)
from nlightreader.items import RequestForm
from nlightreader.models import Manga
Expand Down Expand Up @@ -50,7 +51,7 @@ def __process_errors(self, exception: Exception):
raise exception
except FetchContentError:
self.manga_area.set_state(ContentContainerState.fetch_error)
except NoContentError:
except (NoContentError, RequestsParamsError):
self.manga_area.set_state(ContentContainerState.no_content)

@Slot()
Expand Down

0 comments on commit b68c6da

Please sign in to comment.