Class StatusProto


  • @ExperimentalApi("https://github.com/grpc/grpc-java/issues/4695")
    public final class StatusProto
    extends Object
    Utility methods for working with Status.
    • Method Detail

      • toStatusException

        public static StatusException toStatusException​(com.google.rpc.Status statusProto)
        Convert a Status instance to a StatusException.

        The returned StatusException will wrap a Status whose code and description are set from the code and message in statusProto. statusProto will be serialized and placed into the metadata of the returned StatusException.

        Throws:
        IllegalArgumentException - if the value of statusProto.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 a Status instance to a StatusException with additional metadata.

        The returned StatusException will wrap a Status whose code and description are set from the code and message in statusProto. statusProto will be serialized and added to metadata. metadata will be set as the metadata of the returned StatusException.

        Throws:
        IllegalArgumentException - if the value of statusProto.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 a Status instance to a StatusException with additional metadata and the root exception thrown. The exception isn't propagated over the wire.

        The returned StatusException will wrap a Status whose code and description are set from the code and message in statusProto. statusProto will be serialized and added to metadata. metadata will be set as the metadata of the returned StatusException. The Throwable is the exception that is set as the cause of the returned StatusException.

        Throws:
        IllegalArgumentException - if the value of statusProto.getCode() is not a valid gRPC status code.
        Since:
        1.3.0
      • fromThrowable

        @Nullable
        public static com.google.rpc.Status fromThrowable​(Throwable t)
        Extract a Status instance from the causal chain of a Throwable.
        Returns:
        the extracted Status instance, or null if none exists.
        Throws:
        IllegalArgumentException - if an embedded Status is found and its code does not match the gRPC Status code.
        Since:
        1.3.0
      • fromStatusAndTrailers

        public static com.google.rpc.Status fromStatusAndTrailers​(Status status,
                                                                  @Nullable
                                                                  Metadata trailers)
        Extracts the google.rpc.Status from trailers, and makes sure they match the gRPC status. If the trailers do not contain a google.rpc.Status, it uses status param to generate a google.rpc.Status.
        Returns:
        the embedded google.rpc.Status
        Since:
        1.11.0