~dongpo-deng/sahana-eden/test

« back to all changes in this revision

Viewing changes to controllers/errors.py

  • Committer: Deng Dongpo
  • Date: 2010-08-01 09:29:44 UTC
  • Revision ID: dongpo@dhcp-21193.iis.sinica.edu.tw-20100801092944-8t9obt4xtl7otesb
initial

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
 
 
3
"""
 
4
    HTTP Error handler -- implements nicer error pages
 
5
 
 
6
    TODO: add/replace the following to your routes.py in web2py directory
 
7
    routes_onerror = [
 
8
        ('eden/401', '/eden/default/user/login'),
 
9
        ('eden/*', '/eden/errors/index'),
 
10
        ('*/*', '/eden/errors/index'),
 
11
    ]
 
12
 
 
13
    NOTE: if Eden is installed elsewhere or exists under different name in applications folder,
 
14
          just rename it in above list. Comment the last route to disable error
 
15
          catching for other apps in the same web2py environment
 
16
"""
 
17
 
 
18
from gluon.http import defined_status
 
19
response.extra_styles = ['S3/errorpages.css']
 
20
 
 
21
error_messages = {
 
22
  'NA':(T("Oops! Something went wrong..."),[]),
 
23
 
 
24
  '400':(T("Sorry, I could not understand your request"),
 
25
            [T('Check for errors in the URL, maybe the address was mistyped.')]),
 
26
 
 
27
  '403':(T("Sorry, that page is forbidden for some reason."),
 
28
            [T('Check if the URL is pointing to a directory instead of a webpage.'),
 
29
             T('Check for errors in the URL, maybe the address was mistyped.')]),
 
30
 
 
31
  '404':(T("Sorry, we couldn't find that page."),
 
32
            [T('Try checking the URL for errors, maybe it was mistyped.'),
 
33
             T('Try refreshing the page or hitting the back button on your browser.')]),
 
34
 
 
35
  '500':(T("Oops! something went wrong on our side."),
 
36
            [T('Try hitting refresh/reload button or trying the URL from the address bar again.'),
 
37
             T('Please come back after sometime if that doesn\'t help.')]),
 
38
 
 
39
  '502':(T("Sorry, something went wrong."),
 
40
            [T('The server received an incorrect response from another server that it was accessing to fill the request by the browser.'),
 
41
             T('Hit the back button on your browser to try again.'),
 
42
             T('Come back later.')]),
 
43
 
 
44
  '503':(T("Sorry, that service is temporary unavailable."),
 
45
            [T('This might be due to a temporary overloading or maintenance of the server.'),
 
46
             T('Hit the back button on your browser to try again.'),
 
47
             T('Come back later.')]),
 
48
 
 
49
  '504':(T("Sorry, things didn't get done on time."),
 
50
            [T('The server did not receive a timely response from another server that it was accessing to fill the request by the browser.'),
 
51
             T('Hit the back button on your browser to try again.'),
 
52
             T('Come back later. Everyone visiting this site is probably experiencing the same problem as you.')]),
 
53
}
 
54
 
 
55
def index():
 
56
    ''' default generic error page '''
 
57
    try:
 
58
        code = request.vars['code']
 
59
        description = defined_status[int(code)]
 
60
    except KeyError:
 
61
        description = 'unknown error'
 
62
        code='NA'
 
63
 
 
64
    details = " %s, %s " % (code, description)
 
65
    app = request.application
 
66
    try:
 
67
        message, suggestions = error_messages[code]
 
68
    except KeyError:
 
69
        message, suggestions = error_messages['NA']
 
70
 
 
71
    return dict(res=request.vars, message=message, details=details, suggestions=suggestions, app=app)