示例#1
0
    def handle_exception(self, exception, debug_mode):    
        logging.exception(exception)
        self.response.clear()

        if debug_mode:
            lines = ''.join(traceback.format_exception(*sys.exc_info()))
            self.response.write('<pre>%s</pre>' % (cgi.escape(lines, quote=True)))
        else:
            # If the exception is a HTTPException, use its error code.
            # Otherwise use a generic 500 error code.
            if isinstance(exception, webapp2.HTTPException):
                code = exception.code
            else:
                code = 500
            
            self.response.set_status(code)
            self.response.out.write(jinja_environment.get_template("generic_error.html").render({'code' : 500}))
示例#2
0
    def handle_exception(self, exception, debug_mode):    
        logging.exception("handler exception: " + exception)
        self.response.clear()

        if debug_mode:
            lines = ''.join(traceback.format_exception(*sys.exc_info()))
            self.response.write('<pre>%s</pre>' % (cgi.escape(lines, quote=True)))
        else:
            # If the exception is a HTTPException, use its error code.
            # Otherwise use a generic 500 error code.
            if isinstance(exception, webapp2.HTTPException):
                code = exception.code
            else:
                code = 500
            
            self.response.set_status(code)
            self.response.out.write(jinja_environment.get_template("generic_error.html").render({'code' : 500}))
示例#3
0
 def prep_html_response(self, template_name, template_vars={}):
     # set header for IE to use edge (no "compatibility")
     self.response.headers.add_header("X-UA-Compatible", "IE=Edge,chrome=1")
     # Preset values for the template
     values = {
       'url_for'      : self.uri_for,
       'logged_in'    : self.logged_in,
       'current_user' : self.current_user if self.logged_in else None
     }
     
     # Add manually supplied template values
     values.update(template_vars)
     
     logging.info("session: %s" % self.session)
     logging.info("template vars: %s" % values)
     
     try:
         template = jinja_environment.get_template(template_name)
         self.response.out.write(template.render(**values))
     except TemplateNotFound:
         self.abort(404)
示例#4
0
    def prep_html_response(self, template_name, template_vars={}):
        # set header for IE to use edge (no "compatibility")
        self.response.headers.add_header("X-UA-Compatible", "IE=Edge,chrome=1")
        # Preset values for the template
        values = {
            'url_for': self.uri_for,
            'logged_in': self.logged_in,
            'current_user': self.current_user if self.logged_in else None
        }

        # Add manually supplied template values
        values.update(template_vars)

        logging.info("session: %s" % self.session)
        logging.info("template vars: %s" % values)

        try:
            template = jinja_environment.get_template(template_name)
            self.response.out.write(template.render(**values))
        except TemplateNotFound:
            self.abort(404)
示例#5
0
def handle_500(request, response, exception): 
    response.set_status(500)
    response.out.write(jinja_environment.get_template("generic_error.html").render({'code' : 500}))
示例#6
0
def handle_404(request, response, exception):
    response.set_status(404)
    response.out.write(jinja_environment.get_template("404.html").render({'code' : 404}))
示例#7
0
def handle_500(request, response, exception):
    response.set_status(500)
    response.out.write(
        jinja_environment.get_template("generic_error.html").render(
            {'code': 500}))
示例#8
0
def handle_404(request, response, exception):
    response.set_status(404)
    response.out.write(
        jinja_environment.get_template("404.html").render({'code': 404}))