use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusRuntimeException in project fabric-sdk-java by hyperledger.
the class ChannelTest method testQueryInstalledChaincodesStatusRuntimeException.
@Test
public void testQueryInstalledChaincodesStatusRuntimeException() throws Exception {
thrown.expect(ProposalException.class);
thrown.expectMessage("ABORTED");
final Channel channel = createRunningChannel(null);
Peer peer = channel.getPeers().iterator().next();
final SettableFuture<FabricProposalResponse.ProposalResponse> settableFuture = SettableFuture.create();
settableFuture.setException(new StatusRuntimeException(Status.ABORTED));
setField(peer, "endorserClent", new MockEndorserClient(settableFuture));
hfclient.queryChannels(peer);
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusRuntimeException in project ballerina by ballerina-lang.
the class MessageUtils method getConnectorError.
/**
* Returns error struct of input type
* Error type can be either ServerError or ClientError. This utility method is used inside Observer onError
* method to construct error struct from message.
*
* @param errorType this is either ServerError or ClientError.
* @param error this is StatusRuntimeException send by opposite party.
* @return error struct.
*/
public static BStruct getConnectorError(BStructType errorType, Throwable error) {
BStruct errorStruct = new BStruct(errorType);
if (error instanceof StatusRuntimeException) {
StatusRuntimeException statusException = (StatusRuntimeException) error;
int status = statusException.getStatus() != null ? statusException.getStatus().getCode().value() : -1;
String message = statusException.getMessage();
errorStruct.setStringField(0, message);
errorStruct.setIntField(0, status);
} else {
if (error.getMessage() == null) {
errorStruct.setStringField(0, UNKNOWN_ERROR);
} else {
errorStruct.setStringField(0, error.getMessage());
}
}
return errorStruct;
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusRuntimeException in project ballerina by ballerina-lang.
the class MessageUtils method handleFailure.
/**
* Handles faliures in GRPC callable unit callback.
*
* @param streamObserver observer used the send the error back
* @param error error message struct
*/
static void handleFailure(StreamObserver<Message> streamObserver, BStruct error) {
int statusCode = Integer.parseInt(String.valueOf(error.getIntField(0)));
String errorMsg = error.getStringField(0);
LOG.error(errorMsg);
ErrorHandlerUtils.printError("error: " + BLangVMErrors.getPrintableStackTrace(error));
if (streamObserver != null) {
streamObserver.onError(new StatusRuntimeException(Status.fromCodeValue(statusCode).withDescription(errorMsg)));
}
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusRuntimeException in project ballerina by ballerina-lang.
the class ErrorResponse method execute.
@Override
public void execute(Context context) {
BStruct endpointClient = (BStruct) context.getRefArgument(CLIENT_RESPONDER_REF_INDEX);
BValue responseValue = context.getRefArgument(RESPONSE_MESSAGE_REF_INDEX);
if (responseValue instanceof BStruct) {
BStruct responseStruct = (BStruct) responseValue;
int statusCode = Integer.parseInt(String.valueOf(responseStruct.getIntField(0)));
String errorMsg = responseStruct.getStringField(0);
StreamObserver responseObserver = MessageUtils.getResponseObserver(endpointClient);
if (responseObserver == null) {
context.setError(MessageUtils.getConnectorError(context, new StatusRuntimeException(Status.fromCode(Status.INTERNAL.getCode()).withDescription("Error while sending the error. Response" + " observer not found."))));
} else {
responseObserver.onError(new StatusRuntimeException(Status.fromCodeValue(statusCode).withDescription(errorMsg)));
}
}
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusRuntimeException in project ballerina by ballerina-lang.
the class Send method execute.
@Override
public void execute(Context context) {
BStruct clientEndpoint = (BStruct) context.getRefArgument(CLIENT_RESPONDER_REF_INDEX);
BValue responseValue = context.getRefArgument(RESPONSE_MESSAGE_REF_INDEX);
StreamObserver<Message> responseObserver = MessageUtils.getResponseObserver(clientEndpoint);
Descriptors.Descriptor outputType = (Descriptors.Descriptor) clientEndpoint.getNativeData(MessageConstants.RESPONSE_MESSAGE_DEFINITION);
if (responseObserver == null) {
context.setError(MessageUtils.getConnectorError(context, new StatusRuntimeException(Status.fromCode(Status.INTERNAL.getCode()).withDescription("Error while initializing connector. " + "response sender doesnot exist"))));
} else {
try {
// If there is no response message like conn -> send(), system doesn't send the message.
if (!MessageUtils.isEmptyResponse(outputType)) {
Message responseMessage = MessageUtils.generateProtoMessage(responseValue, outputType);
responseObserver.onNext(responseMessage);
}
} catch (Throwable e) {
LOG.error("Error while sending client response.", e);
context.setError(MessageUtils.getConnectorError(context, e));
}
}
}
Aggregations