Class StatusProto
- java.lang.Object
-
- io.grpc.protobuf.StatusProto
-
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/4695") public final class StatusProto extends java.lang.Object
Utility methods for working withStatus.
-
-
Field Summary
Fields Modifier and Type Field Description private static Metadata.Key<com.google.rpc.Status>STATUS_DETAILS_KEY
-
Constructor Summary
Constructors Modifier Constructor Description privateStatusProto()
-
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(java.lang.Throwable t)Extract aStatusinstance from the causal chain of aThrowable.private static MetadatatoMetadata(com.google.rpc.Status statusProto)private static MetadatatoMetadata(com.google.rpc.Status statusProto, Metadata metadata)private static StatustoStatus(com.google.rpc.Status statusProto)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, java.lang.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.
-
-
-
Field Detail
-
STATUS_DETAILS_KEY
private static final Metadata.Key<com.google.rpc.Status> STATUS_DETAILS_KEY
-
-
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:
java.lang.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:
java.lang.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:
java.lang.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:
java.lang.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, java.lang.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:
java.lang.IllegalArgumentException- if the value ofstatusProto.getCode()is not a valid gRPC status code.- Since:
- 1.3.0
-
toStatus
private static Status toStatus(com.google.rpc.Status statusProto)
-
toMetadata
private static Metadata toMetadata(com.google.rpc.Status statusProto)
-
toMetadata
private static Metadata toMetadata(com.google.rpc.Status statusProto, Metadata metadata)
-
fromThrowable
@Nullable public static com.google.rpc.Status fromThrowable(java.lang.Throwable t)
Extract aStatusinstance from the causal chain of aThrowable.- Returns:
- the extracted
Statusinstance, ornullif none exists. - Throws:
java.lang.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
-
-