Код: Выделить всё
status_code = 13
message = "INTERNAL: ErrorCode: code"
rich_status = status_pb2.Status(code=status_code, message=message)
context.set_trailing_metadata(
(
("custom-key", "custom-error-value")
)
)
status = rpc_status.to_status(rich_status)
context.abort_with_status(status)
Код: Выделить всё
Metadata.Key CUSTOM_KEY = Metadata.Key.of("custom-key", Metadata.ASCII_STRING_MARSHALLER);
Metadata metadata = new Metadata();
metadata.put(CUSTOM_KEY, "custom-error-value");
StatusRuntimeException exception = Status.INTERNAL
.withDescription("INTERNAL: ErrorCode: code")
.asRuntimeException(metadata);
responseObserver.onError(exception);
grpcio-status==1.60.1
Подробнее здесь: https://stackoverflow.com/questions/787 ... aborting-r