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.StatusfromStatusAndTrailers(Status status, Metadata trailers)Extracts thegoogle.rpc.Statusfrom trailers, and makes sure they match the gRPCstatus.static com.google.rpc.StatusfromThrowable(Throwable t)Extract aStatusinstance from the causal chain of aThrowable.static StatusExceptiontoStatusException(com.google.rpc.Status statusProto)Convert aStatusinstance to aStatusException.static StatusExceptiontoStatusException(com.google.rpc.Status statusProto, Metadata metadata)Convert aStatusinstance to aStatusExceptionwith additional metadata.static StatusExceptiontoStatusException(com.google.rpc.Status statusProto, Metadata metadata, Throwable cause)Convert aStatusinstance to aStatusExceptionwith additional metadata and the root exception thrown.static StatusRuntimeExceptiontoStatusRuntimeException(com.google.rpc.Status statusProto)Convert aStatusinstance to aStatusRuntimeException.static StatusRuntimeExceptiontoStatusRuntimeException(com.google.rpc.Status statusProto, Metadata metadata)Convert aStatusinstance to aStatusRuntimeExceptionwith additional metadata.
-
-
-
Method Detail
-
toStatusRuntimeException
public static StatusRuntimeException toStatusRuntimeException(com.google.rpc.Status statusProto)
Convert aStatusinstance to aStatusRuntimeException.The returned
StatusRuntimeExceptionwill wrap aStatuswhose code and description are set from the code and message instatusProto.statusProtowill 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 aStatusinstance to aStatusRuntimeExceptionwith additional metadata.The returned
StatusRuntimeExceptionwill wrap aStatuswhose code and description are set from the code and message instatusProto.statusProtowill be serialized and added tometadata.metadatawill 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 aStatusinstance to aStatusException.The returned
StatusExceptionwill wrap aStatuswhose code and description are set from the code and message instatusProto.statusProtowill 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 aStatusinstance to aStatusExceptionwith additional metadata.The returned
StatusExceptionwill wrap aStatuswhose code and description are set from the code and message instatusProto.statusProtowill be serialized and added tometadata.metadatawill 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 aStatusinstance to aStatusExceptionwith additional metadata and the root exception thrown. The exception isn't propagated over the wire.The returned
StatusExceptionwill wrap aStatuswhose code and description are set from the code and message instatusProto.statusProtowill be serialized and added tometadata.metadatawill be set as the metadata of the returnedStatusException. TheThrowableis the exception that is set as thecauseof 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 aStatusinstance from the causal chain of aThrowable.- Returns:
- the extracted
Statusinstance, ornullif none exists. - Throws:
IllegalArgumentException- if an embeddedStatusis found and its code does not match the gRPCStatuscode.- Since:
- 1.3.0
-
fromStatusAndTrailers
public static com.google.rpc.Status fromStatusAndTrailers(Status status, @Nullable Metadata trailers)
Extracts thegoogle.rpc.Statusfrom trailers, and makes sure they match the gRPCstatus. If the trailers do not contain agoogle.rpc.Status, it usesstatusparam to generate agoogle.rpc.Status.- Returns:
- the embedded google.rpc.Status
- Since:
- 1.11.0
-
-