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