forked from gratipay/gratipay.com
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherror.spt
63 lines (58 loc) · 1.71 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
from __future__ import absolute_import, division, print_function, unicode_literals
from aspen import json
from aspen.http import status_strings
try:
from pygments.lexers import PythonTracebackLexer
from pygments.formatters import HtmlFormatter
from StringIO import StringIO
pygmentize = True
except ImportError:
from aspen.logging import log
import sys
exc = sys.exc_info()[1]
log("Cannot import pygments: " + str(exc))
pygmentize = False
[----------------------------------------]
style = ''
msg = status_strings.get(response.code, 'Sorry').title()
err = response.body
if request.website.show_tracebacks and pygmentize:
sio = StringIO()
formatter = HtmlFormatter()
tokens = PythonTracebackLexer().get_tokens(response.body)
formatter.format(tokens, sio)
sio.seek(0)
err = sio.read()
style = formatter.get_style_defs()
[----------------------------------------] text/html
<html>
<head>
<title>{{response.code}} {{msg|e}}</title>
<style>
{{style}}
BODY {
margin: 0;
padding: 200px 0 0;
text-align: center;
font: normal 18pt/18pt Georgia, serif;
}
PRE {
text-align: left;
font: normal 10pt/12pt monospace;
margin: 50px 200px 0;
}
</style>
</head>
<body>
{{msg|e}}, program!
<pre>{{err|e}}</pre>
</body>
</html>
[----------------------------------------] application/json via json_dump
{ "error_code": response.code
, "error_message_short": msg
, "error_message_long": err
}
[----------------------------------------] text/plain
{{msg}}, program!
{{err}}