api/server/panic.go

21 lines
344 B
Go
Raw Permalink Normal View History

2018-05-14 14:19:29 +02:00
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)
}
}