Skip to content

Commit

Permalink
404 instead of 500 on invalid pages
Browse files Browse the repository at this point in the history
  • Loading branch information
sbussetti committed Jul 20, 2016
1 parent 0c66558 commit 53580b6
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion fastsitemaps/generator.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from six import StringIO
from django.core.paginator import InvalidPage
from django.http import Http404
from django.utils.xmlutils import SimplerXMLGenerator
from django.conf import settings
from fastsitemaps.sitemaps import RequestSitemap
Expand All @@ -19,7 +21,13 @@ def sitemap_generator(request, maps, page, current_site):
site = site()
elif hasattr(site, 'request'):
site.request = request
for url in site.get_urls(page=page, site=current_site, protocol=protocol):

try:
urls = site.get_urls(page=page, site=current_site, protocol=protocol)
except InvalidPage:
raise Http404('Page not found')

for url in urls:
xml.startElement('url', {})
xml.addQuickElement('loc', url['location'])
try:
Expand Down

0 comments on commit 53580b6

Please sign in to comment.