self._log()
self._finished = True
- def send_error(self, status_code=500):
+ def send_error(self, status_code=500, **kwargs):
"""Sends the given HTTP error code to the browser.
We also send the error HTML for the given error code as returned by
return
self.clear()
self.set_status(status_code)
- message = self.get_error_html(status_code)
+ message = self.get_error_html(status_code, **kwargs)
self.finish(message)
- def get_error_html(self, status_code):
- """Override to implement custom error pages."""
+ def get_error_html(self, status_code, **kwargs):
+ """Override to implement custom error pages.
+
+ If this error was caused by an uncaught exception, the
+ exception object can be found in kwargs e.g. kwargs['exception']
+ """
return "<html><title>%(code)d: %(message)s</title>" \
"<body>%(code)d: %(message)s</body></html>" % {
"code": status_code,
self._locale = self.get_browser_locale()
assert self._locale
return self._locale
-
+
def get_user_locale(self):
"""Override to determine the locale from the authenticated user.
self.application.settings.get("xsrf_cookies"):
self.check_xsrf_cookie()
self.prepare()
- if not self._finished:
+ if not self._finished:
getattr(self, self.request.method.lower())(*args, **kwargs)
if self._auto_finish and not self._finished:
self.finish()
logging.warning(format, *args)
if e.status_code not in httplib.responses:
logging.error("Bad HTTP status code: %d", e.status_code)
- self.send_error(500)
+ self.send_error(500, exception=e)
else:
- self.send_error(e.status_code)
+ self.send_error(e.status_code, exception=e)
else:
logging.error("Uncaught exception %s\n%r", self._request_summary(),
self.request, exc_info=e)
- self.send_error(500)
+ self.send_error(500, exception=e)
def _ui_module(self, name, module):
def render(*args, **kwargs):
handler = None
args = []
handlers = self._get_host_handlers(request)
- if not handlers:
+ if not handlers:
handler = RedirectHandler(
request, "http://" + self.default_host + "/")
else:
RequestHandler.__init__(self, application, request)
self._url = url
self._permanent = permanent
-
+
def get(self):
self.redirect(self._url, permanent=self._permanent)
headers["Transfer-Encoding"] = "chunked"
chunk = self.transform_chunk(chunk, finishing)
return headers, chunk
-
+
def transform_chunk(self, block, finishing):
if self._chunking:
# Don't write out empty chunks because that means END-OF-STREAM
Parameters:
pattern: Regular expression to be matched. Any groups in the regex
- will be passed in to the handler's get/post/etc methods as
+ will be passed in to the handler's get/post/etc methods as
arguments.
handler_class: RequestHandler subclass to be invoked.
kwargs (optional): A dictionary of additional arguments to be passed
to the handler's constructor.
- name (optional): A name for this handler. Used by
+ name (optional): A name for this handler. Used by
Application.reverse_url.
"""
if not pattern.endswith('$'):