Class StatusProto


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

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static com.google.rpc.Status fromStatusAndTrailers​(io.grpc.Status status, io.grpc.Metadata trailers)
      Extracts the google.rpc.Status from trailers, and makes sure they match the gRPC status.
      static com.google.rpc.Status fromThrowable​(Throwable t)
      Extract a Status instance from the causal chain of a Throwable.
      static io.grpc.StatusException toStatusException​(com.google.rpc.Status statusProto)
      Convert a Status instance to a StatusException.
      static io.grpc.StatusException toStatusException​(com.google.rpc.Status statusProto, io.grpc.Metadata metadata)
      Convert a Status instance to a StatusException with additional metadata.
      static io.grpc.StatusException toStatusException​(com.google.rpc.Status statusProto, io.grpc.Metadata metadata, Throwable cause)
      Convert a Status instance to a StatusException with additional metadata and the root exception thrown.
      static io.grpc.StatusRuntimeException toStatusRuntimeException​(com.google.rpc.Status statusProto)
      Convert a Status instance to a StatusRuntimeException.
      static io.grpc.StatusRuntimeException toStatusRuntimeException​(com.google.rpc.Status statusProto, io.grpc.Metadata metadata)
      Convert a Status instance to a StatusRuntimeException with additional metadata.
    • Method Detail

      • toStatusRuntimeException

        public static io.grpc.StatusRuntimeException toStatusRuntimeException​(com.google.rpc.Status statusProto)
        Convert a Status instance to a StatusRuntimeException.

        The returned StatusRuntimeException 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 StatusRuntimeException.

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

        public static io.grpc.StatusRuntimeException toStatusRuntimeException​(com.google.rpc.Status statusProto,
                                                                              io.grpc.Metadata metadata)
        Convert a Status instance to a StatusRuntimeException with additional metadata.

        The returned StatusRuntimeException 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 StatusRuntimeException.

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

        public static io.grpc.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 io.grpc.StatusException toStatusException​(com.google.rpc.Status statusProto,
                                                                io.grpc.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 io.grpc.StatusException toStatusException​(com.google.rpc.Status statusProto,
                                                                io.grpc.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​(io.grpc.Status status,
                                                                  @Nullable
                                                                  io.grpc.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