liubao68 closed pull request #499: [SCB-214] AbstractServiceRegistry 
findServiceInstance process null return value, not print too much exception
URL: https://github.com/apache/incubator-servicecomb-java-chassis/pull/499
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git 
a/service-registry/src/main/java/io/servicecomb/serviceregistry/client/http/ServiceRegistryClientImpl.java
 
b/service-registry/src/main/java/io/servicecomb/serviceregistry/client/http/ServiceRegistryClientImpl.java
index dbc4cbe93..960185384 100644
--- 
a/service-registry/src/main/java/io/servicecomb/serviceregistry/client/http/ServiceRegistryClientImpl.java
+++ 
b/service-registry/src/main/java/io/servicecomb/serviceregistry/client/http/ServiceRegistryClientImpl.java
@@ -169,13 +169,19 @@ private void retry(RequestContext requestContext, 
Handler<RestResponse> response
           bodyBuffer -> {
             try {
               
mInstances.setRevision(response.getHeader("X-Resource-Revision"));
-              if (response.statusCode() == 304) {
-                mInstances.setNeedRefresh(false);
-              } else {
-                
mInstances.setInstancesResponse(JsonUtils.readValue(bodyBuffer.getBytes(), 
FindInstancesResponse.class));
+              switch (response.statusCode()) {
+                case 304:
+                  mInstances.setNeedRefresh(false);
+                  break;
+                case 200:
+                  
mInstances.setInstancesResponse(JsonUtils.readValue(bodyBuffer.getBytes(), 
FindInstancesResponse.class));
+                  break;
+                default:
+                  LOGGER.warn(bodyBuffer.toString());
+                  break;
               }
             } catch (Exception e) {
-              LOGGER.warn(bodyBuffer.toString(), e);
+              LOGGER.warn("read value failed and response message is {}", 
bodyBuffer.toString());
             }
             countDownLatch.countDown();
           });
diff --git 
a/service-registry/src/main/java/io/servicecomb/serviceregistry/registry/AbstractServiceRegistry.java
 
b/service-registry/src/main/java/io/servicecomb/serviceregistry/registry/AbstractServiceRegistry.java
index db72748d1..a92e1fe60 100644
--- 
a/service-registry/src/main/java/io/servicecomb/serviceregistry/registry/AbstractServiceRegistry.java
+++ 
b/service-registry/src/main/java/io/servicecomb/serviceregistry/registry/AbstractServiceRegistry.java
@@ -204,6 +204,9 @@ public boolean unregisterInstance() {
   public List<MicroserviceInstance> findServiceInstance(String appId, String 
serviceName,
       String versionRule) {
     MicroserviceInstances instances = findServiceInstances(appId, serviceName, 
versionRule, null);
+    if (instances == null) {
+      return null;
+    }
     return instances.getInstancesResponse().getInstances();
   }
 


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to