[ 
https://issues.apache.org/jira/browse/SCB-656?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16507782#comment-16507782
 ] 

ASF GitHub Bot commented on SCB-656:
------------------------------------

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:
[email protected]


> When provider returns non 200 code Edge Service will all convert to 502
> -----------------------------------------------------------------------
>
>                 Key: SCB-656
>                 URL: https://issues.apache.org/jira/browse/SCB-656
>             Project: Apache ServiceComb
>          Issue Type: Bug
>            Reporter: liubao
>            Assignee: liubao
>            Priority: Major
>
> Provider 404 and some other status code will not given to browser when edge 
> service is used. It's better to give the common error code to browser if 
> possible. 
>  
> e.g. request an URL /api/xxService/pathNotExists, edge will give browser 502, 
> but it's better to give 404



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to