feat: update err func
This commit is contained in:
parent
513928b265
commit
c65291893c
|
@ -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,
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue