Skip to content

Commit 24f1446

Browse files
Fix error on invalid chapter redirect
1 parent 30f30e0 commit 24f1446

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

reader/tests/test_views.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ def test_get(self):
8888

8989
assert str(r1.content) == str(r2.content)
9090

91+
def test_no_match(self):
92+
r = self.client.get('/reader/series/0/6936167464014960228/')
93+
assert r.status_code == 404
94+
9195

9296
class TestChapterDownload(ReaderViewTestBase):
9397
def test_get(self):

reader/views.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from django.db.models import Count, F, Prefetch, Q
99
from django.http import FileResponse, Http404
1010
from django.shortcuts import redirect, render
11+
from django.urls.exceptions import NoReverseMatch
1112
from django.utils import timezone as tz
1213
from django.views.decorators.cache import cache_control
1314
from django.views.decorators.http import condition
@@ -253,8 +254,13 @@ def chapter_redirect(request: HttpRequest, slug: str, vol: int,
253254
:param num: The number of the chapter.
254255
255256
:return: A redirect to :func:`chapter_page`.
257+
258+
:raises Http404: If the chapter does not exist.
256259
"""
257-
return redirect('reader:page', slug, vol, num, 1, permanent=True)
260+
try:
261+
return redirect('reader:page', slug, vol, num, 1, permanent=True)
262+
except NoReverseMatch as e:
263+
raise Http404 from e
258264

259265

260266
@condition(etag_func=_cbz_etag, last_modified_func=_latest)

0 commit comments

Comments
 (0)