feat: update err func

This commit is contained in:
daniel.w 2024-08-07 16:27:15 +08:00
parent 513928b265
commit c65291893c
1 changed files with 23 additions and 1 deletions

View File

@ -1,11 +1,11 @@
package error
import (
"code.30cm.net/wanderland/library-go/pkg/errors/code"
"errors"
"fmt"
"net/http"
"code.30cm.net/wanderland/library-go/pkg/errors/code"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
@ -194,3 +194,25 @@ func (e *Err) GRPCStatus() *status.Status {
return status.New(codes.Code(e.FullCode()), e.Error())
}
// 工廠函數
// NewErr 創建新的 Err
func NewErr(scope, category, detail uint32, msg string) *Err {
return &Err{
category: category,
code: detail,
scope: scope,
msg: msg,
}
}
// NewGRPCErr 創建新的 gRPC Err
func NewGRPCErr(scope, detail uint32, msg string) *Err {
return &Err{
category: code.CatGRPC,
code: detail,
scope: scope,
msg: msg,
}
}