pylons.middleware
– WSGI Middleware¶
Pylons’ WSGI middlewares
Module Contents¶
-
class
pylons.middleware.
StatusCodeRedirect
(app, errors=(400, 401, 403, 404), path='/error/document')¶ Internally redirects a request based on status code
StatusCodeRedirect watches the response of the app it wraps. If the response is an error code in the errors sequence passed the request will be re-run with the path URL set to the path passed in.
This operation is non-recursive and the output of the second request will be used no matter what it is.
Should an application wish to bypass the error response (ie, to purposely return a 401), set
environ['pylons.status_code_redirect'] = True
in the application.-
__init__
(app, errors=(400, 401, 403, 404), path='/error/document')¶ Initialize the ErrorRedirect
errors
- A sequence (list, tuple) of error code integers that should be caught.
path
- The path to set for the next request down to the application.
-
-
pylons.middleware.
ErrorHandler
(app, global_conf, **errorware)¶ ErrorHandler Toggle
If debug is enabled, this function will return the app wrapped in the WebError
EvalException
middleware which displays interactive debugging sessions when a traceback occurs.Otherwise, the app will be wrapped in the WebError
ErrorMiddleware
, and theerrorware
dict will be passed into it. TheErrorMiddleware
handles sending an email to the address listed in the .ini file, underemail_to
.
Note
- The
errorware
dictionary is constructed from the settings in the DEFAULT section of development.ini. the recognised keys and settings at initialization are: error_email
= conf.get(‘email_to’)error_log
= conf.get(‘error_log’, None)smtp_server
= conf.get(‘smtp_server’,’localhost’)error_subject_prefix
= conf.get(‘error_subject_prefix’, ‘WebApp Error: ‘)from_address
= conf.get(‘from_address’, conf.get(‘error_email_from’, 'pylons@yourapp.com‘))error_message
= conf.get(‘error_message’, ‘An internal server error occurred’)
Referenced classes¶
Pylons middleware uses WebError
to effect the error-handling. The two classes implicated are:
ErrorMiddleware¶
weberror.errormiddleware
weberror.errormiddleware.ErrorMiddleware