forked from revel/revel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
panic.go
31 lines (27 loc) · 771 Bytes
/
panic.go
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
package revel
import (
"runtime/debug"
)
// PanicFilter wraps the action invocation in a protective defer blanket that
// converts panics into 500 error pages.
func PanicFilter(c *Controller, fc []Filter) {
defer func() {
if err := recover(); err != nil {
handleInvocationPanic(c, err)
}
}()
fc[0](c, fc[1:])
}
// This function handles a panic in an action invocation.
// It cleans up the stack trace, logs it, and displays an error page.
func handleInvocationPanic(c *Controller, err interface{}) {
error := NewErrorFromPanic(err)
if error == nil {
ERROR.Print(err, "\n", string(debug.Stack()))
c.Response.Out.WriteHeader(500)
c.Response.Out.Write(debug.Stack())
return
}
ERROR.Print(err, "\n", error.Stack)
c.Result = c.RenderError(error)
}