diff --git a/pkg/middleware/middleware.go b/pkg/middleware/middleware.go index cb3f4480821..a546d7e76fc 100644 --- a/pkg/middleware/middleware.go +++ b/pkg/middleware/middleware.go @@ -187,6 +187,7 @@ func (ctx *Context) Handle(status int, title string, err error) { } ctx.Data["Title"] = title + ctx.Data["AppSubUrl"] = setting.AppSubUrl ctx.HTML(status, strconv.Itoa(status)) } diff --git a/pkg/middleware/recovery.go b/pkg/middleware/recovery.go index 8843f2e55d3..b63bc623549 100644 --- a/pkg/middleware/recovery.go +++ b/pkg/middleware/recovery.go @@ -19,53 +19,14 @@ import ( "bytes" "fmt" "io/ioutil" - "net/http" "runtime" "gopkg.in/macaron.v1" - "github.com/go-macaron/inject" "github.com/grafana/grafana/pkg/log" "github.com/grafana/grafana/pkg/setting" ) -const ( - panicHtml = ` -
%s-
%s- -` -) - var ( dunno = []byte("???") centerDot = []byte("ยท") @@ -151,21 +112,34 @@ func Recovery() macaron.Handler { panicLogger.Error("Request error", "error", err, "stack", string(stack)) - // Lookup the current responsewriter - val := c.GetVal(inject.InterfaceOf((*http.ResponseWriter)(nil))) - res := val.Interface().(http.ResponseWriter) + c.Data["Title"] = "Server Error" + c.Data["AppSubUrl"] = setting.AppSubUrl + + if theErr, ok := err.(error); ok { + c.Data["Title"] = theErr.Error() + } - // respond with panic message while in development mode - var body []byte if setting.Env == setting.DEV { - res.Header().Set("Content-Type", "text/html") - body = []byte(fmt.Sprintf(panicHtml, err, err, stack)) + c.Data["ErrorMsg"] = string(stack) } - res.WriteHeader(http.StatusInternalServerError) - if nil != body { - res.Write(body) - } + c.HTML(500, "500") + + // // Lookup the current responsewriter + // val := c.GetVal(inject.InterfaceOf((*http.ResponseWriter)(nil))) + // res := val.Interface().(http.ResponseWriter) + // + // // respond with panic message while in development mode + // var body []byte + // if setting.Env == setting.DEV { + // res.Header().Set("Content-Type", "text/html") + // body = []byte(fmt.Sprintf(panicHtml, err, err, stack)) + // } + // + // res.WriteHeader(http.StatusInternalServerError) + // if nil != body { + // res.Write(body) + // } } }() diff --git a/public/views/500.html b/public/views/500.html index 9565304e7ff..cb2e99595f1 100644 --- a/public/views/500.html +++ b/public/views/500.html @@ -5,28 +5,32 @@ -
[[.ErrorMsg]]+