Skip to content

Commit 280b5ea

Browse files
committed
update
1 parent 0236ef4 commit 280b5ea

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

cerror/cerror.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/chenjie199234/Corelib/util/common"
1212
"google.golang.org/grpc/codes"
1313
"google.golang.org/grpc/status"
14+
"google.golang.org/protobuf/encoding/protojson"
1415
)
1516

1617
func MakeCError(code int32, httpcode int32, msg string) *Error {
@@ -82,7 +83,8 @@ func Decode(estr string) *Error {
8283
if estr[0] == '{' && estr[len(estr)-1] == '}' {
8384
//json format
8485
tmp := &Error{}
85-
if e := json.Unmarshal(common.STB(estr), tmp); e != nil {
86+
//protojson can support "number string" or "number" for field:code
87+
if e := (protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}).Unmarshal(common.STB(estr), tmp); e != nil {
8688
return MakeCError(-1, 500, estr)
8789
}
8890
if tmp.Code == 0 {

0 commit comments

Comments
 (0)