rpc_util: update deprecated messages (#2545)
The status package now has `Convert()` and `Code()` utilities. This patch updates the deprecation description for `ErrorDesc()` and `Code()` to recommend using those functions, and forward the deprecated functions to use the `status.Code()` and `status.Convert()` functions.
This commit is contained in:
Родитель
98de7e24ac
Коммит
e441557ee9
14
rpc_util.go
14
rpc_util.go
|
@ -685,23 +685,17 @@ func rpcInfoFromContext(ctx context.Context) (s *rpcInfo, ok bool) {
|
|||
// Code returns the error code for err if it was produced by the rpc system.
|
||||
// Otherwise, it returns codes.Unknown.
|
||||
//
|
||||
// Deprecated: use status.FromError and Code method instead.
|
||||
// Deprecated: use status.Code instead.
|
||||
func Code(err error) codes.Code {
|
||||
if s, ok := status.FromError(err); ok {
|
||||
return s.Code()
|
||||
}
|
||||
return codes.Unknown
|
||||
return status.Code(err)
|
||||
}
|
||||
|
||||
// ErrorDesc returns the error description of err if it was produced by the rpc system.
|
||||
// Otherwise, it returns err.Error() or empty string when err is nil.
|
||||
//
|
||||
// Deprecated: use status.FromError and Message method instead.
|
||||
// Deprecated: use status.Convert and Message method instead.
|
||||
func ErrorDesc(err error) string {
|
||||
if s, ok := status.FromError(err); ok {
|
||||
return s.Message()
|
||||
}
|
||||
return err.Error()
|
||||
return status.Convert(err).Message()
|
||||
}
|
||||
|
||||
// Errorf returns an error containing an error code and a description;
|
||||
|
|
Загрузка…
Ссылка в новой задаче