Skip to content

Commit

Permalink
chore:grpc error log (sofastack#860)
Browse files Browse the repository at this point in the history
  • Loading branch information
leizhiyuan committed Feb 21, 2020
1 parent 991376f commit b813804
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 52 deletions.
Expand Up @@ -175,22 +175,8 @@ public synchronized T refer() {
// proxyIns = (T) newBlockingChannel.invoke(null, channel);
blockingStubIns = (T) newBlockingChannel.invoke(null, channel);

} catch (ClassNotFoundException e) {
LOGGER.error("ClassNotFoundException");
} catch (Throwable e) {
throw e;
} catch (IllegalAccessException e) {
LOGGER.error("IllegalAccessException");
throw e;
} catch (NoSuchMethodException e) {
LOGGER.error("NoSuchMethodException");
throw e;
} catch (InvocationTargetException e) {
LOGGER.error("InvocationTargetException");
throw e;
} catch (IllegalArgumentException e) {
LOGGER.error("IllegalArgumentException");
throw e;
} finally {
}

// second, make proxy for that stub, using a fake channel.
Expand Down
Expand Up @@ -16,8 +16,9 @@
*/
package com.alipay.sofa.rpc.transport.grpc;

import com.alibaba.fastjson.JSONObject;
import com.alipay.sofa.rpc.common.utils.ClassUtils;
import com.alipay.sofa.rpc.core.exception.RpcErrorType;
import com.alipay.sofa.rpc.core.exception.SofaRpcException;
import com.alipay.sofa.rpc.core.request.SofaRequest;
import com.alipay.sofa.rpc.core.response.SofaResponse;
import com.alipay.sofa.rpc.log.Logger;
Expand All @@ -26,7 +27,6 @@
import io.grpc.Channel;
import io.grpc.stub.StreamObserver;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.concurrent.TimeUnit;

Expand Down Expand Up @@ -57,8 +57,9 @@ public class GrpcClientInvoker {

/**
* The constructor
*
* @param sofaRequest The SofaRequest
* @param channel The Channel
* @param channel The Channel
*/
public GrpcClientInvoker(SofaRequest sofaRequest, Channel channel) {
this.channel = channel;
Expand All @@ -74,17 +75,20 @@ public GrpcClientInvoker(SofaRequest sofaRequest, Channel channel) {
try {
requestClass.cast(request);
} catch (ClassCastException e) {
LOGGER.error("Request type error!");
throw e;
}
this.timeout = sofaRequest.getTimeout();
}

public SofaResponse invoke() {
Object response = invokeRequestMethod();
SofaResponse r = new SofaResponse();
r.setAppResponse(response);
return r;
SofaResponse sofaResponse = new SofaResponse();
try {
Object response = invokeRequestMethod();
sofaResponse.setAppResponse(response);
} catch (SofaRpcException e) {
sofaResponse.setErrorMsg(e.getMessage());
}
return sofaResponse;
}

private CallOptions buildCallOptions() {
Expand All @@ -103,20 +107,8 @@ public io.grpc.stub.AbstractStub getBlockingStub() {
newBlockingStubMethod.setAccessible(true);
stub = (io.grpc.stub.AbstractStub) newBlockingStubMethod.invoke(null, channel);

} catch (ClassNotFoundException e) {
LOGGER.error("ClassNotFoundException");

} catch (IllegalAccessException e) {
LOGGER.error("IllegalAccessException");

} catch (NoSuchMethodException e) {
LOGGER.error("NoSuchMethodException");

} catch (InvocationTargetException e) {
LOGGER.error("InvocationTargetException");

} catch (IllegalArgumentException e) {
LOGGER.error("IllegalArgumentException");
} catch (Throwable e) {
throw new SofaRpcException(RpcErrorType.UNKNOWN, e.getMessage(), e);
}
return stub;
}
Expand All @@ -129,20 +121,8 @@ public Object invokeRequestMethod() {
requestMethod.setAccessible(true);
r = requestMethod.invoke(getBlockingStub(), methodArgs[0]);

} catch (ClassNotFoundException e) {
LOGGER.error("ClassNotFoundException");

} catch (IllegalAccessException e) {
LOGGER.error("IllegalAccessException");

} catch (NoSuchMethodException e) {
LOGGER.error("NoSuchMethodException");

} catch (InvocationTargetException e) {
LOGGER.error("InvocationTargetException");

} catch (IllegalArgumentException e) {
LOGGER.error("IllegalArgumentException");
} catch (Throwable e) {
throw new SofaRpcException(RpcErrorType.CLIENT_UNDECLARED_ERROR, e.getMessage(), e);
}
return r;
}
Expand Down
Expand Up @@ -85,7 +85,6 @@ public void disconnect() {
channel.shutdown().awaitTermination(5, TimeUnit.SECONDS);
} catch (InterruptedException e) {
LOGGER.warn("GRPC channel shut down interrupted.");
e.printStackTrace();
}
channel = null;
}
Expand Down

0 comments on commit b813804

Please sign in to comment.