BoltClientTransport extends ClientTransport { protected SofaRpcException convertToRpcException(Exception e) { SofaRpcException exception; if (e instanceof SofaRpcException) { exception = (SofaRpcException) e; } else if (e instanceof InvokeTimeoutException) { exception = new SofaTimeOutException(e); } else if (e instanceof InvokeServerBusyException) { exception = new SofaRpcException(RpcErrorType.SERVER_BUSY, e); } else if (e instanceof SerializationException) { boolean isServer = ((SerializationException) e).isServerSide(); exception = isServer ? new SofaRpcException(RpcErrorType.SERVER_SERIALIZE, e) : new SofaRpcException(RpcErrorType.CLIENT_SERIALIZE, e); } else if (e instanceof DeserializationException) { boolean isServer = ((DeserializationException) e).isServerSide(); exception = isServer ? new SofaRpcException(RpcErrorType.SERVER_DESERIALIZE, e) : new SofaRpcException(RpcErrorType.CLIENT_DESERIALIZE, e); } else if (e instanceof ConnectionClosedException) { exception = new SofaRpcException(RpcErrorType.CLIENT_NETWORK, e); } else if (e instanceof InvokeSendFailedException) { exception = new SofaRpcException(RpcErrorType.CLIENT_NETWORK, e); } else if (e instanceof InvokeServerException) { exception = new SofaRpcException(RpcErrorType.SERVER_UNDECLARED_ERROR, e.getCause()); } else { exception = new SofaRpcException(RpcErrorType.CLIENT_UNDECLARED_ERROR, e); } return exception; } protected  BoltClientTransport(ClientTransportConfig transportConfig); @Override void connect(); @Override void disconnect(); @Override void destroy(); @Override boolean isAvailable(); @Override void setChannel(AbstractChannel channel); @Override AbstractChannel getChannel(); @Override int currentRequests(); @Override ResponseFuture asyncSend(SofaRequest request, int timeout); @Override SofaResponse syncSend(SofaRequest request, int timeout); @Override void oneWaySend(SofaRequest request, int timeout); @Override void receiveRpcResponse(SofaResponse response); @Override void handleRpcRequest(SofaRequest request); @Override InetSocketAddress remoteAddress(); @Override InetSocketAddress localAddress(); Connection fetchConnection();  }
@Test public void testConvertToRpcException() { ClientTransportConfig config1 = new ClientTransportConfig(); config1.setProviderInfo(new ProviderInfo().setHost("127.0.0.1").setPort(12222)) .setContainer("bolt"); BoltClientTransport transport = new BoltClientTransport(config1); Assert.assertTrue(transport .convertToRpcException(new SofaRpcException(RpcErrorType.CLIENT_UNDECLARED_ERROR, "")) instanceof SofaRpcException); Assert.assertTrue(transport.convertToRpcException(new InvokeTimeoutException()) instanceof SofaTimeOutException); Assert.assertTrue(transport.convertToRpcException(new InvokeServerBusyException()) .getErrorType() == RpcErrorType.SERVER_BUSY); Assert.assertTrue(transport.convertToRpcException(new SerializationException("xx", true)) .getErrorType() == RpcErrorType.SERVER_SERIALIZE); Assert.assertTrue(transport.convertToRpcException(new SerializationException("xx", false)) .getErrorType() == RpcErrorType.CLIENT_SERIALIZE); Assert.assertTrue(transport.convertToRpcException(new DeserializationException("xx", true)) .getErrorType() == RpcErrorType.SERVER_DESERIALIZE); Assert.assertTrue(transport.convertToRpcException(new DeserializationException("xx", false)) .getErrorType() == RpcErrorType.CLIENT_DESERIALIZE); Assert.assertTrue(transport.convertToRpcException(new ConnectionClosedException()) .getErrorType() == RpcErrorType.CLIENT_NETWORK); Assert.assertTrue(transport.convertToRpcException(new InvokeSendFailedException()) .getErrorType() == RpcErrorType.CLIENT_NETWORK); Assert.assertTrue(transport.convertToRpcException(new InvokeServerException()) .getErrorType() == RpcErrorType.SERVER_UNDECLARED_ERROR); Assert.assertTrue(transport.convertToRpcException(new UnsupportedOperationException()) .getErrorType() == RpcErrorType.CLIENT_UNDECLARED_ERROR); }