forked from liberapay/liberapay.com
-
Notifications
You must be signed in to change notification settings - Fork 0
/
error.spt
97 lines (86 loc) · 3.53 KB
/
error.spt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
from pando.http import status_strings
from pando.utils import utcnow
from liberapay.exceptions import LazyResponse
from liberapay.i18n.base import HTTP_ERRORS
[----------------------------------------]
sentry_ident = state.get('sentry_ident')
code = response.code
msg = _(HTTP_ERRORS[code]) if code in HTTP_ERRORS else status_strings.get(code, '')
try:
assert msg
except Exception as e:
website.tell_sentry(e)
if isinstance(response, LazyResponse):
response.render_body(state)
err = response.text
if code == 500 and not err:
err = _("Looks like you've found a bug! Sorry for the inconvenience, we'll get it fixed ASAP!")
if response.whence_raised == (None, None):
response.set_whence_raised()
filepath, linenum = response.whence_raised
error_location = '%s:%i' % (filepath, linenum) if filepath else 'unknown'
referer = request.headers.get(b'Referer')
user_agent = request.headers.get(b'User-Agent')
[----------------------------------------] text/html
% extends "templates/layouts/base.html"
% set title = '' if response.html_template else msg
% block content
% if response.html_template
% include response.html_template
% else
% if code >= 400 and code <= 499
% if code == 404
<p>{{ _(
"The requested page could not be found. Please "
"{link_open}contact us{link_close} if you need assistance.",
link_open='<a href="https://liberapay.com/about/contact">'|safe,
link_close='</a>'|safe,
) }}</p>
% else
<p>{{ _(
"Your request has been rejected by our software. Please "
"{link_open}contact us{link_close} if you need assistance.",
link_open='<a href="https://liberapay.com/about/contact">'|safe,
link_close='</a>'|safe,
) }}</p>
% endif
% endif
% if err
% if '\n' in err
<pre>{{ err }}</pre>
% else
<p>{{ _("Error message:") }}</p>
<div class="alert alert-danger">{{ err }}</div>
% endif
% endif
% if sentry_ident
<p>{{ _(
"The details of this error have been recorded. If you decide to contact us, "
"please include the following error identification code in your message: {0}.",
'<code>%s</code>'|safe % sentry_ident
) }}</p>
% else
<br>
<p>{{ _("If you decide to contact us please include the following debugging information in your message:") }}</p>
<pre>URL: {{ website.canonical_scheme }}://{{ request.hostname }}{{ request.line.uri.decoded }}{{ '\n'
}}Method: {{ request.method }}{{ '\n'
}}Referer: {{ repr(referer) }}{{ '\n'
}}User-Agent: {{ repr(user_agent) }}{{ '\n'
}}Time: {{ utcnow() }}{{ '\n'
}}Response code: {{ code }}{{ '\n'
}}Response message: {{ repr(err) }}{{ '\n'
}}Error location: {{ error_location }}{{ '\n'
}}User: {{ user }}{{ '\n'
}}Website version: {{ website.version }}</pre>
% endif
% endif
% endblock
[----------------------------------------] application/json via json_dump
{ "error_code": code
, "error_message_short": msg
, "error_message_long": err
, "error_id": sentry_ident
, "error_location": error_location
}
[----------------------------------------] text/plain
{{err or msg}}