mirror of https://github.com/grpc/grpc-go.git
status: wrap status proto in a struct (#3556)
This commit is contained in:
parent
10ccd46359
commit
695df7e2f9
|
|
@ -97,7 +97,7 @@ func (s *Status) Err() error {
|
||||||
if s.Code() == codes.OK {
|
if s.Code() == codes.OK {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return (*Error)(s.Proto())
|
return &Error{e: s.Proto()}
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithDetails returns a new status with the provided details messages appended to the status.
|
// WithDetails returns a new status with the provided details messages appended to the status.
|
||||||
|
|
@ -136,18 +136,19 @@ func (s *Status) Details() []interface{} {
|
||||||
return details
|
return details
|
||||||
}
|
}
|
||||||
|
|
||||||
// Error is an alias of a status proto. It implements error and Status,
|
// Error wraps a pointer of a status proto. It implements error and Status,
|
||||||
// and a nil *Error should never be returned by this package.
|
// and a nil *Error should never be returned by this package.
|
||||||
type Error spb.Status
|
type Error struct {
|
||||||
|
e *spb.Status
|
||||||
|
}
|
||||||
|
|
||||||
func (e *Error) Error() string {
|
func (e *Error) Error() string {
|
||||||
p := (*spb.Status)(e)
|
return fmt.Sprintf("rpc error: code = %s desc = %s", codes.Code(e.e.GetCode()), e.e.GetMessage())
|
||||||
return fmt.Sprintf("rpc error: code = %s desc = %s", codes.Code(p.GetCode()), p.GetMessage())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GRPCStatus returns the Status represented by se.
|
// GRPCStatus returns the Status represented by se.
|
||||||
func (e *Error) GRPCStatus() *Status {
|
func (e *Error) GRPCStatus() *Status {
|
||||||
return FromProto((*spb.Status)(e))
|
return FromProto(e.e)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Is implements future error.Is functionality.
|
// Is implements future error.Is functionality.
|
||||||
|
|
@ -157,5 +158,5 @@ func (e *Error) Is(target error) bool {
|
||||||
if !ok {
|
if !ok {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return proto.Equal((*spb.Status)(e), (*spb.Status)(tse))
|
return proto.Equal(e.e, tse.e)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue