'Called within an except block to allow converting exceptions
to abitrary responses. Anything returned (except None) will
be used as response.'

def _handle_exception(self, exception):

    try:
        return super(HttpRequest, self)._handle_exception(exception)
    except SessionExpiredException:
        redirect = None
        req = request.httprequest
        if (req.method == 'POST'):
            request.session.save_request_data()
            redirect = '/web/proxy/post{r.path}?{r.query_string}'.format(r=req)
        elif (not request.params.get('noredirect')):
            redirect = req.url
        if redirect:
            query = werkzeug.urls.url_encode({'redirect': redirect})
            return werkzeug.utils.redirect(('/web/login?%s' % query))
    except werkzeug.exceptions.HTTPException as e:
        return e
