Class StatusProto


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

      • STATUS_DETAILS_KEY

        private static final Metadata.Key<com.google.rpc.Status> STATUS_DETAILS_KEY
    • Constructor Detail

      • StatusProto

        private StatusProto()
    • Method Detail

      • toStatusRuntimeException

        public static 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:
        java.lang.IllegalArgumentException - if the value of statusProto.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 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:
        java.lang.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)
        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:
        java.lang.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:
        java.lang.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,
                                                        java.lang.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:
        java.lang.IllegalArgumentException - if the value of statusProto.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 a Status instance from the causal chain of a Throwable.
        Returns:
        the extracted Status instance, or null if none exists.
        Throws:
        java.lang.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