use of com.google.rpc.ErrorInfo in project java-pubsublite by googleapis.
the class TestResetSignal method newCheckedException.
public static CheckedApiException newCheckedException() {
ErrorInfo errorInfo = ErrorInfo.newBuilder().setReason("RESET").setDomain("pubsublite.googleapis.com").build();
Status status = Status.newBuilder().setCode(Code.ABORTED.ordinal()).addDetails(Any.pack(errorInfo)).build();
return new CheckedApiException(StatusProto.toStatusRuntimeException(status), Code.ABORTED);
}
use of com.google.rpc.ErrorInfo in project java-pubsublite by googleapis.
the class ResetSignalTest method isResetSignal_notRetryable.
@Test
public void isResetSignal_notRetryable() {
ErrorInfo errorInfo = ErrorInfo.newBuilder().setReason("RESET").setDomain("pubsublite.googleapis.com").build();
Status status = Status.newBuilder().setCode(Code.FAILED_PRECONDITION.ordinal()).addDetails(Any.pack(errorInfo)).build();
CheckedApiException exception = new CheckedApiException(StatusProto.toStatusRuntimeException(status), Code.FAILED_PRECONDITION);
assertThat(ResetSignal.isResetSignal(exception)).isFalse();
}
use of com.google.rpc.ErrorInfo in project java-pubsublite by googleapis.
the class ResetSignalTest method isResetSignal_wrongReason.
@Test
public void isResetSignal_wrongReason() {
ErrorInfo errorInfo = ErrorInfo.newBuilder().setReason("OTHER").setDomain("pubsublite.googleapis.com").build();
Status status = Status.newBuilder().setCode(Code.ABORTED.ordinal()).addDetails(Any.pack(errorInfo)).build();
CheckedApiException exception = new CheckedApiException(StatusProto.toStatusRuntimeException(status), Code.ABORTED);
assertThat(ResetSignal.isResetSignal(exception)).isFalse();
}
use of com.google.rpc.ErrorInfo in project java-pubsub by googleapis.
the class StreamingSubscriberConnectionTest method getMockStatusException.
private StatusException getMockStatusException(Map<String, String> metadata) {
ErrorInfo errorInfo = ErrorInfo.newBuilder().putAllMetadata(metadata).build();
Status status = Status.newBuilder().setCode(StatusCode.Code.OK.ordinal()).addDetails(Any.pack(errorInfo)).build();
return StatusProto.toStatusException(status);
}
use of com.google.rpc.ErrorInfo in project java-pubsub by googleapis.
the class StreamingSubscriberConnection method getMetadataMapFromThrowable.
private Map<String, String> getMetadataMapFromThrowable(Throwable t) throws InvalidProtocolBufferException {
// This converts a Throwable (from a "OK" grpc response) to a map of metadata
// will be of the format:
// {
// "ACK-ID-1": "PERMANENT_*",
// "ACK-ID-2": "TRANSIENT_*"
// }
com.google.rpc.Status status = StatusProto.fromThrowable(t);
Map<String, String> metadataMap = new HashMap<>();
if (status != null) {
for (Any any : status.getDetailsList()) {
if (any.is(ErrorInfo.class)) {
ErrorInfo errorInfo = any.unpack(ErrorInfo.class);
metadataMap = errorInfo.getMetadataMap();
}
}
}
return metadataMap;
}
Aggregations