GRPCStatus converts the Error into a gRPC status message.
()
| 94 | |
| 95 | // GRPCStatus converts the Error into a gRPC status message. |
| 96 | func (e *Error) GRPCStatus() *status.Status { |
| 97 | if s, ok := e.grpcStatus.Load().(*status.Status); ok && s != nil { |
| 98 | return s |
| 99 | } |
| 100 | s := status.New(codes.Code(e.Code()), e.String()) |
| 101 | if ErrorDetailsToProto != nil { |
| 102 | if pb := ErrorDetailsToProto(e); pb != nil { |
| 103 | var err error |
| 104 | s, err = s.WithDetails(protoadapt.MessageV1Of(pb)) |
| 105 | if err != nil { |
| 106 | panic(err) // ErrorDetailsToProto generated an invalid proto. |
| 107 | } |
| 108 | } |
| 109 | } |
| 110 | e.grpcStatus.Store(s) |
| 111 | return s |
| 112 | } |
| 113 | |
| 114 | // UnaryServerInterceptor makes sure that returned TTN errors contain a CorrelationID. |
| 115 | func UnaryServerInterceptor() grpc.UnaryServerInterceptor { |