Package io.servicetalk.grpc.api
Class GrpcStatus
- java.lang.Object
-
- io.servicetalk.grpc.api.GrpcStatus
-
public final class GrpcStatus extends java.lang.Object
Class representing gRPC statuses.- See Also:
GrpcStatusCode
-
-
Constructor Summary
Constructors Constructor Description GrpcStatus(GrpcStatusCode code)
Constructs a status with no cause or description.GrpcStatus(GrpcStatusCode code, java.lang.Throwable cause)
Constructs a status with cause but no additional description.GrpcStatus(GrpcStatusCode code, java.lang.Throwable cause, java.lang.CharSequence description)
Constructs a status with cause and additional description.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description GrpcStatusException
asException()
Returns the current status wrapped in aGrpcStatusException
.GrpcStatusException
asException(java.util.function.Supplier<com.google.rpc.Status> applicationStatusSupplier)
Returns the current status wrapped in aGrpcStatusException
including the supplied details.java.lang.Throwable
cause()
Returns the cause, can be null.GrpcStatusCode
code()
Returns the status code.java.lang.String
description()
Returns additional descriptions, can be null.boolean
equals(java.lang.Object o)
static GrpcStatus
fromCodeValue(int codeValue)
Obtains the status given an integer code value.static GrpcStatus
fromCodeValue(java.lang.String codeValue)
Obtains the status given a code value string.static GrpcStatus
fromThrowable(java.lang.Throwable t)
Translates a throwable into a status.static GrpcStatus
fromThrowableNullable(java.lang.Throwable t)
Translates a throwable into a status.int
hashCode()
java.lang.String
toString()
-
-
-
Constructor Detail
-
GrpcStatus
public GrpcStatus(GrpcStatusCode code)
Constructs a status with no cause or description.- Parameters:
code
- status code.
-
GrpcStatus
public GrpcStatus(GrpcStatusCode code, @Nullable java.lang.Throwable cause)
Constructs a status with cause but no additional description.- Parameters:
code
- status code.cause
- cause.
-
GrpcStatus
public GrpcStatus(GrpcStatusCode code, @Nullable java.lang.Throwable cause, @Nullable java.lang.CharSequence description)
Constructs a status with cause and additional description.- Parameters:
code
- status code.cause
- cause.description
- additional description.
-
-
Method Detail
-
fromCodeValue
public static GrpcStatus fromCodeValue(java.lang.String codeValue)
Obtains the status given a code value string.- Parameters:
codeValue
- code value string.- Returns:
- status associated with the code value, or
GrpcStatusCode.UNKNOWN
.
-
fromCodeValue
public static GrpcStatus fromCodeValue(int codeValue)
Obtains the status given an integer code value.- Parameters:
codeValue
- integer code value.- Returns:
- status associated with the code value, or
GrpcStatusCode.UNKNOWN
.
-
fromThrowable
public static GrpcStatus fromThrowable(java.lang.Throwable t)
Translates a throwable into a status.- Parameters:
t
- the throwable.- Returns:
- embedded status if the throwable is a
GrpcStatusException
, or anGrpcStatusCode.UNKNOWN
status with the throwable as the cause.
-
fromThrowableNullable
@Nullable public static GrpcStatus fromThrowableNullable(java.lang.Throwable t)
Translates a throwable into a status.- Parameters:
t
- the throwable.- Returns:
- embedded status if the throwable is a
GrpcStatusException
, ornull
.
-
asException
public GrpcStatusException asException()
Returns the current status wrapped in aGrpcStatusException
.- Returns:
- the current status wrapped in a
GrpcStatusException
.
-
asException
public GrpcStatusException asException(java.util.function.Supplier<com.google.rpc.Status> applicationStatusSupplier)
Returns the current status wrapped in aGrpcStatusException
including the supplied details. The status code used byStatus
and the one of theGrpcStatus
must be the same. Users should usually useGrpcStatusException.of(Status)
.- Parameters:
applicationStatusSupplier
- theSupplier
for theStatus
.- Returns:
- the current status wrapped in a
GrpcStatusException
.
-
code
public GrpcStatusCode code()
Returns the status code.- Returns:
- the status code.
-
cause
@Nullable public java.lang.Throwable cause()
Returns the cause, can be null.- Returns:
- the cause, can be null.
-
description
@Nullable public java.lang.String description()
Returns additional descriptions, can be null.- Returns:
- additional descriptions, can be null.
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-