Class ErrorCatcher
source code
object --+
|
turbogears.controllers.Controller --+
|
turbogears.controllers.RootController --+
|
ErrorCatcher
- Known Subclasses:
-
Base class for root controllers catching errors and showing error
page.
To use enable custom error pages, the root controller must subclass
the ``ErrorCatcher`` class and the CherryPy filter hook must be enabled
by setting ``error_catcher.on = True`` in the deployment
configuration.
When the error catcher is enabled and an HTML error (including an
unhandled exception) occurs in the controller, an error page is displayed
using a template, whose name is looked up in the
``_error_page_templates`` class attribute by the HTML status code.
Currently, there are default templates for the status codes 401, 403
and 404, called ``401_error``, ``403_error`` and ``404_error`` resp. and
``unhandled_exception`` for all other errors. The templates are searched
in the ``templates`` sub-package of the application.
Also, if ``mail.on`` is ``True`` sends an email to the admin, when an
error occurs. No email is sent if the HTML status code is contained in
the list set by the option ``error_catcher.no_email_on``. The default is
not to send emails for 401, 403 and 404 errors.
For email sending to work, at least the configuration options
'error_catcher.sender_email' and 'error_catcher.admin_email' must be set
to valid email addresses.
See the docstring for the method 'send_exception_email' for more email
related configuration information.
|
__init__(self,
*args,
**kw)
x.__init__(...) initializes x; see x.__class__.__doc__ for signature |
source code
|
|
|
cp_on_http_error(self,
status,
message)
Handle HTTP errors by sending an error page and email. |
source code
|
|
|
_cp_on_http_error(self,
status,
message)
Handle HTTP errors by sending an error page and email. |
source code
|
|
|
send_error_page(self,
**data)
Render error page using template looked up in self._error_templates. |
source code
|
|
|
|
|
_send_email_by_smtp(self,
from_addr,
to_addr,
message)
Send email via SMTP. |
source code
|
|
|
_get_error_message(self,
status,
default=None)
Return string error for HTTP status code. |
source code
|
|
|
_render_error_template(self,
template,
format=' html ' ,
content_type=' text/html ' ,
data={ } ) |
source code
|
|
Inherited from turbogears.controllers.RootController (private):
_cp_log_access ,
_cp_log_message
Inherited from object :
__delattr__ ,
__getattribute__ ,
__hash__ ,
__new__ ,
__reduce__ ,
__reduce_ex__ ,
__repr__ ,
__setattr__ ,
__str__
|
|
_error_codes = { None: u' Unknown Error ' , 400: u' 400 - Bad Reque ...
|
|
_error_page_templates = { None: ' .templates.unhandled_exception ...
|
|
_error_mail_templates = { None: ' cheetah:.templates.email_unhan ...
|
|
admin_group_name = ' admin '
|
Inherited from turbogears.controllers.RootController :
accesslog ,
is_app_root ,
msglog ,
msglogfunc
|
Inherited from object :
__class__
|
x.__init__(...) initializes x; see x.__class__.__doc__ for
signature
- Overrides:
object.__init__
- (inherited documentation)
|
Send an email with the error info to the admin.
Uses TurboMail if installed and activated, otherwise tries to send
email with the ``smtplib`` module. The SMTP settings can be configured
with the following settings:
``mail.server`` - Mail server to connect to (default 'localhost').
``mail.username`` - User name for SMTP authentication. If the value
is unset or evaluates to False no SMTP login is
performed.
``mail.password`` - Password for SMTP authentication. may be an empty
string.
See also the class docstring for information on setting the
sender and recipient address.
|
_error_codes
- Value:
{ None: u' Unknown Error ' ,
400: u' 400 - Bad Request ' ,
401: u' 401 - Unauthorized ' ,
403: u' 403 - Forbidden ' ,
404: u' 404 - Not Found ' ,
500: u' 500 - Internal Server Error ' ,
501: u' 501 - Not Implemented ' ,
502: u' 502 - Bad Gateway ' }
|
|
_error_page_templates
- Value:
{ None: ' .templates.unhandled_exception ' ,
401: ' .templates.401_error ' ,
403: ' .templates.403_error ' ,
404: ' .templates.404_error ' }
|
|
_error_mail_templates
- Value:
{ None: ' cheetah:.templates.email_unhandled_exception ' }
|
|