|
|
@ -5,7 +5,6 @@ import ( |
|
|
|
"fmt" |
|
|
|
"fmt" |
|
|
|
|
|
|
|
|
|
|
|
httpstatus "github.com/go-kratos/kratos/v2/transport/http/status" |
|
|
|
httpstatus "github.com/go-kratos/kratos/v2/transport/http/status" |
|
|
|
|
|
|
|
|
|
|
|
"google.golang.org/genproto/googleapis/rpc/errdetails" |
|
|
|
"google.golang.org/genproto/googleapis/rpc/errdetails" |
|
|
|
"google.golang.org/grpc/status" |
|
|
|
"google.golang.org/grpc/status" |
|
|
|
"google.golang.org/protobuf/proto" |
|
|
|
"google.golang.org/protobuf/proto" |
|
|
@ -102,16 +101,19 @@ func FromError(err error) *Error { |
|
|
|
} |
|
|
|
} |
|
|
|
gs, ok := status.FromError(err) |
|
|
|
gs, ok := status.FromError(err) |
|
|
|
if ok { |
|
|
|
if ok { |
|
|
|
|
|
|
|
ret := New( |
|
|
|
|
|
|
|
httpstatus.FromGRPCCode(gs.Code()), |
|
|
|
|
|
|
|
UnknownReason, |
|
|
|
|
|
|
|
gs.Message(), |
|
|
|
|
|
|
|
) |
|
|
|
for _, detail := range gs.Details() { |
|
|
|
for _, detail := range gs.Details() { |
|
|
|
switch d := detail.(type) { |
|
|
|
switch d := detail.(type) { |
|
|
|
case *errdetails.ErrorInfo: |
|
|
|
case *errdetails.ErrorInfo: |
|
|
|
return New( |
|
|
|
ret.Reason = d.Reason |
|
|
|
httpstatus.FromGRPCCode(gs.Code()), |
|
|
|
return ret.WithMetadata(d.Metadata) |
|
|
|
d.Reason, |
|
|
|
|
|
|
|
gs.Message(), |
|
|
|
|
|
|
|
).WithMetadata(d.Metadata) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return ret |
|
|
|
} |
|
|
|
} |
|
|
|
return New(UnknownCode, UnknownReason, err.Error()) |
|
|
|
return New(UnknownCode, UnknownReason, err.Error()) |
|
|
|
} |
|
|
|
} |
|
|
|