Skip to content

Commit 5bd6b25

Browse files
committed
fix: fix crash on empty search
1 parent 05f67b3 commit 5bd6b25

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

eddrit/routes/pages/search.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from starlette.requests import Request
2-
from starlette.responses import Response
2+
from starlette.responses import RedirectResponse, Response
33
from starlette.routing import Route
44

55
from eddrit.reddit.fetch import search_posts, search_subreddits
@@ -12,6 +12,8 @@
1212

1313
async def search(request: Request) -> Response:
1414
input_text = request.query_params.get("q", "")
15+
if input_text == "":
16+
return RedirectResponse("/")
1517

1618
subreddit_search_results = await search_subreddits(
1719
request.state.http_client, input_text

templates/header.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
<li>
3131
<form role="search" class="nav-search" action="/search" method="get">
3232
<input type="search" id="search" name="q" placeholder="Search">
33-
<input type="submit" value="" />
33+
<input type="submit" value="" />
3434
</form>
3535
</li>
3636
</ul>

0 commit comments

Comments
 (0)