error.py 1.0KB

12345678910111213141516171819202122232425262728293031
  1. # -*- coding: utf-8 -*-
  2. """Error controller"""
  3. from tg import request, expose
  4. __all__ = ['ErrorController']
  5. class ErrorController(object):
  6. """
  7. Generates error documents as and when they are required.
  8. The ErrorDocuments middleware forwards to ErrorController when error
  9. related status codes are returned from the application.
  10. This behaviour can be altered by changing the parameters to the
  11. ErrorDocuments middleware in your config/middleware.py file.
  12. """
  13. @expose('pod.templates.error')
  14. def document(self, *args, **kwargs):
  15. """Render the error document"""
  16. resp = request.environ.get('pylons.original_response')
  17. default_message = ("<p>We're sorry but we weren't able to process "
  18. " this request.</p>")
  19. values = dict(prefix=request.environ.get('SCRIPT_NAME', ''),
  20. code=request.params.get('code', resp.status_int),
  21. message=request.params.get('message', default_message))
  22. return values