1 from django.http import HttpResponse
2 from django.utils.decorators import decorator_from_middleware
4 from philo.contrib.winer.exceptions import HttpNotAcceptable
7 class HttpNotAcceptableMiddleware(object):
8 """Middleware to catch :exc:`~philo.contrib.winer.exceptions.HttpNotAcceptable` and return an :class:`HttpResponse` with a 406 response code. See :rfc:`2616`."""
9 def process_exception(self, request, exception):
10 if isinstance(exception, HttpNotAcceptable):
11 return HttpResponse(status=406)
14 http_not_acceptable = decorator_from_middleware(HttpNotAcceptableMiddleware)