'Catches internal Horizon exception classes.
Exception classes such as NotAuthorized, NotFound and Http302
are caught and handles them gracefully.'

def process_exception(self, request, exception):

    if isinstance(exception, (exceptions.NotAuthorized, exceptions.NotAuthenticated)):
        auth_url = settings.LOGIN_URL
        next_url = iri_to_uri(request.get_full_path())
        if (next_url != auth_url):
            field_name = REDIRECT_FIELD_NAME
        else:
            field_name = None
        login_url = request.build_absolute_uri(auth_url)
        response = redirect_to_login(next_url, login_url=login_url, redirect_field_name=field_name)
        if isinstance(exception, exceptions.NotAuthorized):
            logout_reason = _('Unauthorized.    Please    try    logging    in    again.')
            utils.add_logout_reason(request, response, logout_reason, 'error')
            response.delete_cookie('messages')
        if request.is_ajax():
            response_401 = http.HttpResponse(status=401)
            response_401['X-Horizon-Location'] = response['location']
            return response_401
        return response
    if isinstance(exception, exceptions.NotFound):
        raise http.Http404(exception)
    if isinstance(exception, exceptions.Http302):
        return shortcuts.redirect(exception.location)
