20260507213409
This commit is contained in:
1 parent
3070eac71b
commit
4c7f516a03
204 files changed
+3623
No files matched your search
@@ -0,0 +1,10 @@
|
||||
package errors
|
||||
|
||||
import "github.com/pkg/errors"
|
||||
|
||||
func WithStack(err error) error {
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package errors
|
||||
|
||||
import (
|
||||
"allapp-go/internal/httpx"
|
||||
"allapp-go/pkg/logger"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/gofiber/fiber/v3"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
func ErrorHandler() fiber.ErrorHandler {
|
||||
return func(c fiber.Ctx, err error) error {
|
||||
code := fiber.StatusInternalServerError
|
||||
msg := "系统异常,请稍后再试!"
|
||||
|
||||
var e *fiber.Error
|
||||
if errors.As(err, &e) {
|
||||
code = e.Code
|
||||
msg = e.Message
|
||||
}
|
||||
|
||||
logger.FromCtx(c.Context()).Error("HTTP 请求异常",
|
||||
zap.Int("status", code),
|
||||
zap.String("error", fmt.Sprintf("%+v", err)),
|
||||
)
|
||||
|
||||
return httpx.SystemError(c, msg)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user