You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
769 B
24 lines
769 B
package middleware
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"github.com/TremblingV5/DouTok/pkg/errno"
|
|
"github.com/cloudwego/hertz/pkg/app"
|
|
"github.com/cloudwego/hertz/pkg/app/middlewares/server/recovery"
|
|
"github.com/cloudwego/hertz/pkg/common/hlog"
|
|
"github.com/cloudwego/hertz/pkg/common/utils"
|
|
"github.com/cloudwego/hertz/pkg/protocol/consts"
|
|
)
|
|
|
|
func Recovery() app.HandlerFunc {
|
|
return recovery.Recovery(recovery.WithRecoveryHandler(
|
|
func(ctx context.Context, c *app.RequestContext, err interface{}, stack []byte) {
|
|
hlog.SystemLogger().CtxErrorf(ctx, "[Recovery] err=%v\nstack=%s", err, stack)
|
|
c.JSON(consts.StatusInternalServerError, utils.H{
|
|
"code": errno.BadRequest,
|
|
"message": fmt.Sprintf("[Recovery] err=%v\nstack=%s", err, stack),
|
|
})
|
|
},
|
|
))
|
|
}
|
|
|