Commit 29bb7e88 authored by Sergios Aftsidis's avatar Sergios Aftsidis

Add exception handling when reversing URL

When reverse resolving URL mappings, if the user supplies a wrong
url mapping under /api/ (e.g. /api/blabla), the resolution fails
and an HTTP500 error is thrown. This catches that case (`NoReverseMatch`)
and throws an HTTP404 instead.
parent 89332f61
......@@ -6,7 +6,7 @@ from django.core.urlresolvers import reverse, NoReverseMatch
# view should be the name of the url from the rest api
def map_view(request, view='pops', city=None, location=None):
if view:
# try:
try:
# raise Exception
if city:
if location:
......@@ -15,8 +15,8 @@ def map_view(request, view='pops', city=None, location=None):
url = reverse('api:' + view, args=(city,))
else:
url = reverse('api:' + view)
# except NoReverseMatch:
# raise Http404
except NoReverseMatch:
raise Http404
if request.GET.get('tag'):
return render(request, 'pops/map.html', {'view': '%s?tag=%s' % (url, request.GET.get('tag')), 'filter': request.GET.get('tag')})
else:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment