The errordocument module is accessible via the paste module.
The middleware in this module can be used to intercept responses with specified status codes and internally forward the request to an appropriate URL where the content can be displayed to the user as an error document.
Intercepts a response with a particular status code and returns the content from a specified URL instead.
The arguments are:
For example, you might want to create a static file to display a "File Not Found" message at the URL /error404.html and then use forward middleware to catch all 404 status codes and display the page you created. In this example app is your exisiting WSGI applicaiton:
from paste.errordocument import forward
app = forward(app, codes={404:'/error404.html'})
Paste Deploy entry point to create a error document wrapper.
Use like:
[filter-app:main] use = egg:Paste#errordocument next = real-app 500 = /lib/msg/500.html 404 = /lib/msg/404.html
Middleware that lets you test a response against a custom mapper object to programatically determine whether to internally forward to another URL and if so, which URL to forward to.
If you don't need the full power of this middleware you might choose to use the simpler forward middleware instead.
The arguments are:
Here is an example where a 404 File Not Found status response would be redirected to the URL /error?code=404&message=File%20Not%20Found. This could be useful for passing the status code and message into another application to display an error document:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | from paste.errordocument import StatusBasedForward from paste.recursive import RecursiveMiddleware from urllib import urlencode def error_mapper(code, message, environ, global_conf, kw) if code in [404, 500]: params = urlencode({'message':message, 'code':code}) url = '/error?'%(params) return url else: return None app = RecursiveMiddleware( StatusBasedForward(app, mapper=error_mapper), ) |
This class contains 2 members.
See the source for more information.