Class StatusProto
- java.lang.Object
-
- io.grpc.protobuf.StatusProto
-
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/4695") public final class StatusProto extends Object
Utility methods for working withStatus
.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static com.google.rpc.Status
fromStatusAndTrailers(Status status, Metadata trailers)
Extracts thegoogle.rpc.Status
from trailers, and makes sure they match the gRPCstatus
.static com.google.rpc.Status
fromThrowable(Throwable t)
Extract aStatus
instance from the causal chain of aThrowable
.static StatusException
toStatusException(com.google.rpc.Status statusProto)
Convert aStatus
instance to aStatusException
.static StatusException
toStatusException(com.google.rpc.Status statusProto, Metadata metadata)
Convert aStatus
instance to aStatusException
with additional metadata.static StatusException
toStatusException(com.google.rpc.Status statusProto, Metadata metadata, Throwable cause)
Convert aStatus
instance to aStatusException
with additional metadata and the root exception thrown.static StatusRuntimeException
toStatusRuntimeException(com.google.rpc.Status statusProto)
Convert aStatus
instance to aStatusRuntimeException
.static StatusRuntimeException
toStatusRuntimeException(com.google.rpc.Status statusProto, Metadata metadata)
Convert aStatus
instance to aStatusRuntimeException
with additional metadata.
-
-
-
Method Detail
-
toStatusRuntimeException
public static StatusRuntimeException toStatusRuntimeException(com.google.rpc.Status statusProto)
Convert aStatus
instance to aStatusRuntimeException
.The returned
StatusRuntimeException
will wrap aStatus
whose code and description are set from the code and message instatusProto
.statusProto
will be serialized and placed into the metadata of the returnedStatusRuntimeException
.- Throws:
IllegalArgumentException
- if the value ofstatusProto.getCode()
is not a valid gRPC status code.- Since:
- 1.3.0
-
toStatusRuntimeException
public static StatusRuntimeException toStatusRuntimeException(com.google.rpc.Status statusProto, Metadata metadata)
Convert aStatus
instance to aStatusRuntimeException
with additional metadata.The returned
StatusRuntimeException
will wrap aStatus
whose code and description are set from the code and message instatusProto
.statusProto
will be serialized and added tometadata
.metadata
will be set as the metadata of the returnedStatusRuntimeException
.- Throws:
IllegalArgumentException
- if the value ofstatusProto.getCode()
is not a valid gRPC status code.- Since:
- 1.3.0
-
toStatusException
public static StatusException toStatusException(com.google.rpc.Status statusProto)
Convert aStatus
instance to aStatusException
.The returned
StatusException
will wrap aStatus
whose code and description are set from the code and message instatusProto
.statusProto
will be serialized and placed into the metadata of the returnedStatusException
.- Throws:
IllegalArgumentException
- if the value ofstatusProto.getCode()
is not a valid gRPC status code.- Since:
- 1.3.0
-
toStatusException
public static StatusException toStatusException(com.google.rpc.Status statusProto, Metadata metadata)
Convert aStatus
instance to aStatusException
with additional metadata.The returned
StatusException
will wrap aStatus
whose code and description are set from the code and message instatusProto
.statusProto
will be serialized and added tometadata
.metadata
will be set as the metadata of the returnedStatusException
.- Throws:
IllegalArgumentException
- if the value ofstatusProto.getCode()
is not a valid gRPC status code.- Since:
- 1.3.0
-
toStatusException
public static StatusException toStatusException(com.google.rpc.Status statusProto, Metadata metadata, Throwable cause)
Convert aStatus
instance to aStatusException
with additional metadata and the root exception thrown. The exception isn't propagated over the wire.The returned
StatusException
will wrap aStatus
whose code and description are set from the code and message instatusProto
.statusProto
will be serialized and added tometadata
.metadata
will be set as the metadata of the returnedStatusException
. TheThrowable
is the exception that is set as thecause
of the returnedStatusException
.- Throws:
IllegalArgumentException
- if the value ofstatusProto.getCode()
is not a valid gRPC status code.- Since:
- 1.3.0
-
fromThrowable
@Nullable public static com.google.rpc.Status fromThrowable(Throwable t)
Extract aStatus
instance from the causal chain of aThrowable
.- Returns:
- the extracted
Status
instance, ornull
if none exists. - Throws:
IllegalArgumentException
- if an embeddedStatus
is found and its code does not match the gRPCStatus
code.- Since:
- 1.3.0
-
fromStatusAndTrailers
public static com.google.rpc.Status fromStatusAndTrailers(Status status, @Nullable Metadata trailers)
Extracts thegoogle.rpc.Status
from trailers, and makes sure they match the gRPCstatus
. If the trailers do not contain agoogle.rpc.Status
, it usesstatus
param to generate agoogle.rpc.Status
.- Returns:
- the embedded google.rpc.Status
- Since:
- 1.11.0
-
-