From 9a81d58bfb1088c8c6286c65150cd13c54c0b4c5 Mon Sep 17 00:00:00 2001 From: Tim Heap Date: Tue, 15 Sep 2015 12:03:46 +1000 Subject: [PATCH] Refactor out a bare except: statement It now catches `Redirect.DoesNotExist`, returning the normal 404 page if no redirect is found. Any other exception should not be caught here. --- wagtail/wagtailredirects/middleware.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/wagtail/wagtailredirects/middleware.py b/wagtail/wagtailredirects/middleware.py index e65d1be987..7ce094a358 100644 --- a/wagtail/wagtailredirects/middleware.py +++ b/wagtail/wagtailredirects/middleware.py @@ -16,12 +16,11 @@ class RedirectMiddleware(object): # Find redirect try: redirect = models.Redirect.get_for_site(request.site).get(old_path=path) + except models.Redirect.DoesNotExist: + # No redirect found, return the 400 page + return response - if redirect.is_permanent: - return http.HttpResponsePermanentRedirect(redirect.link) - else: - return http.HttpResponseRedirect(redirect.link) - except: - pass - - return response + if redirect.is_permanent: + return http.HttpResponsePermanentRedirect(redirect.link) + else: + return http.HttpResponseRedirect(redirect.link)