You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by GitBox <gi...@apache.org> on 2018/06/11 07:57:03 UTC

[GitHub] liubao68 closed pull request #764: [SCB-656]edge service should return back the providers error code

liubao68 closed pull request #764: [SCB-656]edge service should return back the providers error code
URL: https://github.com/apache/incubator-servicecomb-java-chassis/pull/764
 
 
   

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/edge/edge-core/src/main/java/org/apache/servicecomb/edge/core/AbstractEdgeDispatcher.java b/edge/edge-core/src/main/java/org/apache/servicecomb/edge/core/AbstractEdgeDispatcher.java
index a1824fad7..5c7ad05f7 100644
--- a/edge/edge-core/src/main/java/org/apache/servicecomb/edge/core/AbstractEdgeDispatcher.java
+++ b/edge/edge-core/src/main/java/org/apache/servicecomb/edge/core/AbstractEdgeDispatcher.java
@@ -19,6 +19,7 @@
 
 import javax.ws.rs.core.Response.Status;
 
+import org.apache.servicecomb.swagger.invocation.exception.InvocationException;
 import org.apache.servicecomb.transport.rest.vertx.AbstractVertxHttpDispatcher;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -32,8 +33,15 @@
   protected void onFailure(RoutingContext context) {
     LOGGER.error("edge server failed.", context.failure());
     HttpServerResponse response = context.response();
-    response.setStatusCode(Status.BAD_GATEWAY.getStatusCode());
-    response.setStatusMessage(Status.BAD_GATEWAY.getReasonPhrase());
-    response.end();
+    if (context.failure() instanceof InvocationException) {
+      InvocationException exception = (InvocationException) context.failure();
+      response.setStatusCode(exception.getStatusCode());
+      response.setStatusMessage(exception.getErrorData().toString());
+      response.end();
+    } else {
+      response.setStatusCode(Status.BAD_GATEWAY.getStatusCode());
+      response.setStatusMessage(Status.BAD_GATEWAY.getReasonPhrase());
+      response.end();
+    }
   }
 }
diff --git a/edge/edge-core/src/test/java/org/apache/servicecomb/edge/core/TestAbstractEdgeDispatcher.java b/edge/edge-core/src/test/java/org/apache/servicecomb/edge/core/TestAbstractEdgeDispatcher.java
index cae30b3d3..b675045cb 100644
--- a/edge/edge-core/src/test/java/org/apache/servicecomb/edge/core/TestAbstractEdgeDispatcher.java
+++ b/edge/edge-core/src/test/java/org/apache/servicecomb/edge/core/TestAbstractEdgeDispatcher.java
@@ -20,6 +20,7 @@
 import java.util.HashMap;
 import java.util.Map;
 
+import org.apache.servicecomb.swagger.invocation.exception.InvocationException;
 import org.junit.Assert;
 import org.junit.Test;
 
@@ -75,5 +76,21 @@ HttpServerResponse setStatusMessage(String statusMessage) {
 
     Assert.assertEquals(502, map.get("code"));
     Assert.assertEquals("Bad Gateway", map.get("msg"));
+
+    new Expectations() {
+      {
+        context.failure();
+        returns(new InvocationException(401, "unauthorized", "unauthorized"),
+            new InvocationException(401, "unauthorized", "unauthorized"));
+        context.response();
+        result = response;
+      }
+    };
+
+    dispatcher = new AbstractEdgeDispatcherForTest();
+    dispatcher.onFailure(context);
+
+    Assert.assertEquals(401, map.get("code"));
+    Assert.assertEquals("unauthorized", map.get("msg"));
   }
 }


 

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services