Skip to content

Commit

Permalink
Updated recover middleware
Browse files Browse the repository at this point in the history
Signed-off-by: Vishal Rana <[email protected]>
  • Loading branch information
vishr committed Sep 21, 2017
1 parent b5de47f commit 914a544
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions middleware/recover.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"runtime"

"github.com/labstack/echo"
"github.com/labstack/gommon/color"
)

type (
Expand Down Expand Up @@ -57,23 +56,21 @@ func RecoverWithConfig(config RecoverConfig) echo.MiddlewareFunc {
}

return func(next echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) (err error) {
return func(c echo.Context) error {
if config.Skipper(c) {
return next(c)
}

defer func() {
if r := recover(); r != nil {
switch r := r.(type) {
case error:
err = r
default:
err, ok := r.(error)
if !ok {
err = fmt.Errorf("%v", r)
}
stack := make([]byte, config.StackSize)
length := runtime.Stack(stack, !config.DisableStackAll)
if !config.DisablePrintStack {
c.Logger().Printf("[%s] %s %s\n", color.Red("PANIC RECOVER"), err, stack[:length])
c.Logger().Printf("[PANIC RECOVER] %v %s\n", err, stack[:length])
}
c.Error(err)
}
Expand Down

0 comments on commit 914a544

Please sign in to comment.