public final class GrpcResponse<T>

  1. Object
  2. 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:

  • 0OK. 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

public static final int STATUS_OK = 0
public static final int STATUS_CANCELLED = 1
public static final int STATUS_UNKNOWN = 2
public static final int STATUS_INVALID_ARGUMENT = 3
public static final int STATUS_DEADLINE_EXCEEDED = 4
public static final int STATUS_NOT_FOUND = 5
public static final int STATUS_ALREADY_EXISTS = 6
public static final int STATUS_PERMISSION_DENIED = 7
public static final int STATUS_RESOURCE_EXHAUSTED = 8
public static final int STATUS_FAILED_PRECONDITION = 9
public static final int STATUS_ABORTED = 10
public static final int STATUS_OUT_OF_RANGE = 11
public static final int STATUS_UNIMPLEMENTED = 12
public static final int STATUS_INTERNAL = 13
public static final int STATUS_UNAVAILABLE = 14
public static final int STATUS_DATA_LOSS = 15
public static final int STATUS_UNAUTHENTICATED = 16
public static final int STATUS_TRANSPORT_FAILURE = -1Sentinel status indicating the transport itself failed (no grpc-status trailer was parsed).

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 = 0

STATUS_CANCELLED

public static final int STATUS_CANCELLED = 1

STATUS_UNKNOWN

public static final int STATUS_UNKNOWN = 2

STATUS_INVALID_ARGUMENT

public static final int STATUS_INVALID_ARGUMENT = 3

STATUS_DEADLINE_EXCEEDED

public static final int STATUS_DEADLINE_EXCEEDED = 4

STATUS_NOT_FOUND

public static final int STATUS_NOT_FOUND = 5

STATUS_ALREADY_EXISTS

public static final int STATUS_ALREADY_EXISTS = 6

STATUS_PERMISSION_DENIED

public static final int STATUS_PERMISSION_DENIED = 7

STATUS_RESOURCE_EXHAUSTED

public static final int STATUS_RESOURCE_EXHAUSTED = 8

STATUS_FAILED_PRECONDITION

public static final int STATUS_FAILED_PRECONDITION = 9

STATUS_ABORTED

public static final int STATUS_ABORTED = 10

STATUS_OUT_OF_RANGE

public static final int STATUS_OUT_OF_RANGE = 11

STATUS_UNIMPLEMENTED

public static final int STATUS_UNIMPLEMENTED = 12

STATUS_INTERNAL

public static final int STATUS_INTERNAL = 13

STATUS_UNAVAILABLE

public static final int STATUS_UNAVAILABLE = 14

STATUS_DATA_LOSS

public static final int STATUS_DATA_LOSS = 15

STATUS_UNAUTHENTICATED

public static final int STATUS_UNAUTHENTICATED = 16

STATUS_TRANSPORT_FAILURE

public static final int STATUS_TRANSPORT_FAILURE = -1
Sentinel 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()
true iff getResponseCode() is 0 (gRPC OK).

getResponseErrorMessage

public String getResponseErrorMessage()
The server-supplied grpc-message trailer (or the HTTP error message when the call failed before reaching the trailer).