ovirt-node 2.2.0 release
[ovirt-node.git] / server / ovirtserver / controllers / error.py
blob6a142180d106e51bc7aa676d833317c28f5ff3ca
1 # Copyright (C) 2010, Red Hat, Inc.
2 # Written by Darryl L. Pierce
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 """Error controller"""
20 from tg import request, expose
22 __all__ = ['ErrorController']
25 class ErrorController(object):
26 """
27 Generates error documents as and when they are required.
29 The ErrorDocuments middleware forwards to ErrorController when error
30 related status codes are returned from the application.
32 This behaviour can be altered by changing the parameters to the
33 ErrorDocuments middleware in your config/middleware.py file.
35 """
37 @expose('ovirtserver.templates.error')
38 def document(self, *args, **kwargs):
39 """Render the error document"""
40 resp = request.environ.get('pylons.original_response')
41 default_message = ("<p>We're sorry but we weren't able to process "
42 " this request.</p>")
43 values = dict(prefix=request.environ.get('SCRIPT_NAME', ''),
44 code=request.params.get('code', resp.status_int),
45 message=request.params.get('message', default_message))
46 return values