api/server/panic.go
2018-05-17 12:08:47 +02:00

21 lines
344 B
Go

package main
import (
"git.fuyu.moe/Fuyu/flog"
"github.com/labstack/echo"
)
func recoverMiddleware(next echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) error {
defer func() {
v := recover()
if v != nil {
flog.Critical(`panic: `, v)
_ = c.JSON(500, `Fatal error occurred`)
}
}()
return next(c)
}
}