@@ -19,53 +19,14 @@ import (
19
19
"bytes"
20
20
"fmt"
21
21
"io/ioutil"
22
- "net/http"
23
22
"runtime"
24
23
25
24
"gopkg.in/macaron.v1"
26
25
27
- "github.com/go-macaron/inject"
28
26
"github.com/grafana/grafana/pkg/log"
29
27
"github.com/grafana/grafana/pkg/setting"
30
28
)
31
29
32
- const (
33
- panicHtml = `<html>
34
- <head><title>PANIC: %s</title>
35
- <meta charset="utf-8" />
36
- <style type="text/css">
37
- html, body {
38
- font-family: "Roboto", sans-serif;
39
- color: #333333;
40
- background-color: #ea5343;
41
- margin: 0px;
42
- }
43
- h1 {
44
- color: #d04526;
45
- background-color: #ffffff;
46
- padding: 20px;
47
- border-bottom: 1px dashed #2b3848;
48
- }
49
- pre {
50
- margin: 20px;
51
- padding: 20px;
52
- border: 2px solid #2b3848;
53
- background-color: #ffffff;
54
- white-space: pre-wrap; /* css-3 */
55
- white-space: -moz-pre-wrap; /* Mozilla, since 1999 */
56
- white-space: -pre-wrap; /* Opera 4-6 */
57
- white-space: -o-pre-wrap; /* Opera 7 */
58
- word-wrap: break-word; /* Internet Explorer 5.5+ */
59
- }
60
- </style>
61
- </head><body>
62
- <h1>PANIC</h1>
63
- <pre style="font-weight: bold;">%s</pre>
64
- <pre>%s</pre>
65
- </body>
66
- </html>`
67
- )
68
-
69
30
var (
70
31
dunno = []byte ("???" )
71
32
centerDot = []byte ("·" )
@@ -151,21 +112,34 @@ func Recovery() macaron.Handler {
151
112
152
113
panicLogger .Error ("Request error" , "error" , err , "stack" , string (stack ))
153
114
154
- // Lookup the current responsewriter
155
- val := c .GetVal (inject .InterfaceOf ((* http .ResponseWriter )(nil )))
156
- res := val .Interface ().(http.ResponseWriter )
115
+ c .Data ["Title" ] = "Server Error"
116
+ c .Data ["AppSubUrl" ] = setting .AppSubUrl
157
117
158
- // respond with panic message while in development mode
159
- var body []byte
160
- if setting .Env == setting .DEV {
161
- res .Header ().Set ("Content-Type" , "text/html" )
162
- body = []byte (fmt .Sprintf (panicHtml , err , err , stack ))
118
+ if theErr , ok := err .(error ); ok {
119
+ c .Data ["Title" ] = theErr .Error ()
163
120
}
164
121
165
- res .WriteHeader (http .StatusInternalServerError )
166
- if nil != body {
167
- res .Write (body )
122
+ if setting .Env == setting .DEV {
123
+ c .Data ["ErrorMsg" ] = string (stack )
168
124
}
125
+
126
+ c .HTML (500 , "500" )
127
+
128
+ // // Lookup the current responsewriter
129
+ // val := c.GetVal(inject.InterfaceOf((*http.ResponseWriter)(nil)))
130
+ // res := val.Interface().(http.ResponseWriter)
131
+ //
132
+ // // respond with panic message while in development mode
133
+ // var body []byte
134
+ // if setting.Env == setting.DEV {
135
+ // res.Header().Set("Content-Type", "text/html")
136
+ // body = []byte(fmt.Sprintf(panicHtml, err, err, stack))
137
+ // }
138
+ //
139
+ // res.WriteHeader(http.StatusInternalServerError)
140
+ // if nil != body {
141
+ // res.Write(body)
142
+ // }
169
143
}
170
144
}()
171
145
0 commit comments