public final class GrpcResponse<T>
- Object
- GrpcResponse
Result of a unary gRPC call. Mirrors the shape of
Response so call sites that already use
the REST helpers feel at home, but the integer status code
returned by getResponseCode() is the gRPC status, not
the HTTP one:
0–OK. Wire-level success.1..16– standard gRPC statuses (CANCELLED, UNKNOWN, …).-1– the transport itself failed (network error, HTTP non-200, missing status trailer).getHttpCode()still returns the underlying HTTP code in that case.
Use isOk() for the common “request succeeded” check.
Fields
Constructors
public GrpcResponse(int grpcStatus, int httpCode, T responseData, String responseMessage) |
Methods
public T getResponseData() | The deserialised response message, or null when the call failed or the server returned an empty body. |
public int getResponseCode() | The gRPC status code. |
public int getHttpCode() | The underlying HTTP status code. |
public boolean isOk() | true iff getResponseCode() is 0 (gRPC OK). |
public String getResponseErrorMessage() | The server-supplied grpc-message trailer (or the HTTP error message when the call failed before reaching the trailer). |
Inherited methods
Field details
STATUS_OK
public static final int STATUS_OK = 0STATUS_CANCELLED
public static final int STATUS_CANCELLED = 1STATUS_UNKNOWN
public static final int STATUS_UNKNOWN = 2STATUS_INVALID_ARGUMENT
public static final int STATUS_INVALID_ARGUMENT = 3STATUS_DEADLINE_EXCEEDED
public static final int STATUS_DEADLINE_EXCEEDED = 4STATUS_NOT_FOUND
public static final int STATUS_NOT_FOUND = 5STATUS_ALREADY_EXISTS
public static final int STATUS_ALREADY_EXISTS = 6STATUS_PERMISSION_DENIED
public static final int STATUS_PERMISSION_DENIED = 7STATUS_RESOURCE_EXHAUSTED
public static final int STATUS_RESOURCE_EXHAUSTED = 8STATUS_FAILED_PRECONDITION
public static final int STATUS_FAILED_PRECONDITION = 9STATUS_ABORTED
public static final int STATUS_ABORTED = 10STATUS_OUT_OF_RANGE
public static final int STATUS_OUT_OF_RANGE = 11STATUS_UNIMPLEMENTED
public static final int STATUS_UNIMPLEMENTED = 12STATUS_INTERNAL
public static final int STATUS_INTERNAL = 13STATUS_UNAVAILABLE
public static final int STATUS_UNAVAILABLE = 14STATUS_DATA_LOSS
public static final int STATUS_DATA_LOSS = 15STATUS_UNAUTHENTICATED
public static final int STATUS_UNAUTHENTICATED = 16STATUS_TRANSPORT_FAILURE
public static final int STATUS_TRANSPORT_FAILURE = -1Sentinel status indicating the transport itself failed (no
grpc-status trailer was parsed). Inspect getHttpCode()
for the underlying HTTP error.Constructor details
GrpcResponse
public GrpcResponse(int grpcStatus, int httpCode, T responseData, String responseMessage)Method details
getResponseData
public T getResponseData()The deserialised response message, or
null when the call
failed or the server returned an empty body.getResponseCode
public int getResponseCode()The gRPC status code.
0 is success; non-zero codes follow
the standard gRPC status enumeration. -1 (STATUS_TRANSPORT_FAILURE)
signals a transport-level error – the call never reached
grpc-status.getHttpCode
public int getHttpCode()The underlying HTTP status code. Usually
200 even for a
non-zero gRPC status, because the server returns gRPC errors
in trailers rather than via HTTP status. Useful when
getResponseCode() is STATUS_TRANSPORT_FAILURE.isOk
public boolean isOk()getResponseErrorMessage
public String getResponseErrorMessage()The server-supplied
grpc-message trailer (or the HTTP error
message when the call failed before reaching the trailer).