Total Complexity | 3 |
Total Lines | 30 |
Duplicated Lines | 0 % |
1 | # -*- coding: utf-8 -*- |
||
9 | class ErrorController(BaseController): |
||
10 | """ |
||
11 | Generates error documents as and when they are required. |
||
12 | |||
13 | The ErrorDocuments middleware forwards to ErrorController when error |
||
14 | related status codes are returned from the application. |
||
15 | |||
16 | This behaviour can be altered by changing the parameters to the |
||
17 | ErrorDocuments middleware in your config/middleware.py file. |
||
18 | |||
19 | """ |
||
20 | |||
21 | @expose('pyjobsweb.templates.error') |
||
22 | def document(self, *args, **kwargs): |
||
23 | """Render the error document""" |
||
24 | resp = request.environ.get('tg.original_response') |
||
25 | try: |
||
26 | # tg.abort exposes the message as .detail in response |
||
27 | message = resp.detail |
||
28 | except: |
||
29 | message = None |
||
30 | |||
31 | if not message: |
||
32 | message = ("<p>We're sorry but we weren't able to process " |
||
33 | " this request.</p>") |
||
34 | |||
35 | values = dict(prefix=request.environ.get('SCRIPT_NAME', ''), |
||
36 | code=request.params.get('code', resp.status_int), |
||
37 | message=request.params.get('message', message)) |
||
38 | return values |
||
39 |