This commit is contained in:
zhaoxiaorong
2025-02-07 17:08:55 +08:00
parent fd62c5cddb
commit 58139791f3
8 changed files with 220 additions and 6 deletions

View File

@@ -1,7 +1,8 @@
package errcode
import (
"github.com/gofiber/fiber/v2"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
// header error code ,start:100
@@ -88,14 +89,14 @@ var (
)
func NewError(code int, msg string) error {
return fiber.NewError(code, msg)
return status.New(codes.Code(code), msg).Err()
}
// custom error,status code:500
func ErrFatal(msg string) error {
return fiber.NewError(500, msg)
func ErrFatal(code int, msg string) error {
return status.New(codes.Code(code), msg).Err()
}
func ErrNotFound(msg string) error {
return fiber.NewError(404, msg+" Not Found")
func ErrNotFound(code int, msg string) error {
return status.New(codes.Code(code), msg).Err()
}