Closed
Description
There is a situation that I want to retrieve grpc error not fmt.Errorf and looking at the code https://github.com/go-kit/kit/blob/master/transport/grpc/client.go#L93 is returning fmt.Errorf, is there any idiomatic way to retrieve grpc error type when invoking the rpc?
Looking at https://github.com/grpc/grpc-go/blob/master/rpc_util.go#L363 grpc has a method to retrieve error message, we can return an error struct containing grpc error, the struct will be ex.
type rpcError struct{
rpc error
err error
}
func(e *rpcError) Error() string{
return e.err.Error()
}
func (e *rpcError) RPC() error{
return e.rpc
}
at gokit change will be:
return nil, &rpcError{rpc: err, err: fmt.Errorf("Invoke: %v", err)}
at consumer will be:
type rpcError interface {
RPC()
}
rpcerr:=err.(rpcError).RPC()
errstr:=grpc.ErrorDesc(rpcerr)
Just an idea, what do you think?
Metadata
Assignees
Labels
No labels
Activity