Skip to content

Commit b68c6da

Browse files
committed
added requests params check
1 parent ad163b2 commit b68c6da

File tree

4 files changed

+25
-3
lines changed

4 files changed

+25
-3
lines changed

nlightreader/exceptions/parser_content_exc.py

+4
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,7 @@ class NoContentError(Exception):
44

55
class FetchContentError(Exception):
66
pass
7+
8+
9+
class RequestsParamsError(Exception):
10+
pass

nlightreader/parsers/hentai_manga/allhentai_hmanga.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

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

1920
def search_manga(self, form):
2021
url = f"{self.url}/search"
21-
params = {"q": form.search, "+": "Искать!", "fast-filter": "CREATION"}
22+
if not form.search:
23+
raise parser_content_exc.RequestsParamsError(
24+
"Search field is empty",
25+
)
26+
params = {
27+
"q": form.search,
28+
"+": "Искать!",
29+
"fast-filter": "CREATION",
30+
}
2231
response = make_request(
2332
url,
2433
"POST",

nlightreader/parsers/hentai_manga/nhentai_hmanga.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from bs4 import BeautifulSoup, element
33

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

1819
def search_manga(self, form):
1920
url = f"{self.url}/search"
20-
params = {"page": form.page, "q": form.search}
21+
if not form.search:
22+
raise parser_content_exc.RequestsParamsError(
23+
"Search field is empty",
24+
)
25+
params = {
26+
"page": form.page,
27+
"q": form.search,
28+
}
2129
response = get_html(
2230
url,
2331
headers=self.headers,

nlightreader/widgets/NlightTemplates/BaseWidget.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from nlightreader.exceptions.parser_content_exc import (
88
FetchContentError,
99
NoContentError,
10+
RequestsParamsError,
1011
)
1112
from nlightreader.items import RequestForm
1213
from nlightreader.models import Manga
@@ -50,7 +51,7 @@ def __process_errors(self, exception: Exception):
5051
raise exception
5152
except FetchContentError:
5253
self.manga_area.set_state(ContentContainerState.fetch_error)
53-
except NoContentError:
54+
except (NoContentError, RequestsParamsError):
5455
self.manga_area.set_state(ContentContainerState.no_content)
5556

5657
@Slot()

0 commit comments

Comments
 (0)