setGRPCStatus sets a (marshaled) gRPC status in the error definition. This func should be called when the error definition is created. Doing that makes that we have to convert to a gRPC status only once instead of on every call.
()
| 67 | // This func should be called when the error definition is created. Doing that |
| 68 | // makes that we have to convert to a gRPC status only once instead of on every call. |
| 69 | func (d *Definition) setGRPCStatus() { |
| 70 | s := status.New(codes.Code(d.Code()), d.String()) |
| 71 | if ErrorDetailsToProto != nil { |
| 72 | if pb := ErrorDetailsToProto(d); pb != nil { |
| 73 | var err error |
| 74 | s, err = s.WithDetails(protoadapt.MessageV1Of(pb)) |
| 75 | if err != nil { |
| 76 | panic(err) // ErrorDetailsToProto generated an invalid proto. |
| 77 | } |
| 78 | } |
| 79 | } |
| 80 | d.grpcStatus = s |
| 81 | } |
| 82 | |
| 83 | // GRPCStatus returns the Definition as a gRPC status message. |
| 84 | func (d *Definition) GRPCStatus() *status.Status { |
no test coverage detected