Added status text to StatusCodeException bug: issue 8314 Change-Id: I1fb85f4bc7fb9d0687b14fd795d73e12f4fc08d6
diff --git a/user/src/com/google/gwt/rpc/client/impl/RpcCallbackAdapter.java b/user/src/com/google/gwt/rpc/client/impl/RpcCallbackAdapter.java index d147178..dd51a95 100644 --- a/user/src/com/google/gwt/rpc/client/impl/RpcCallbackAdapter.java +++ b/user/src/com/google/gwt/rpc/client/impl/RpcCallbackAdapter.java
@@ -80,7 +80,7 @@ statsContext.bytesStat(methodName, encodedResponse.length(), "responseReceived")); if (statusCode != Response.SC_OK) { - caught = new StatusCodeException(statusCode, encodedResponse); + caught = new StatusCodeException(statusCode, response.getStatusText(), encodedResponse); } else if (encodedResponse == null) { // This can happen if the XHR is interrupted by the server dying caught = new InvocationException("No response payload from " + methodName);
diff --git a/user/src/com/google/gwt/user/client/rpc/StatusCodeException.java b/user/src/com/google/gwt/user/client/rpc/StatusCodeException.java index e600118..3d84f3d 100644 --- a/user/src/com/google/gwt/user/client/rpc/StatusCodeException.java +++ b/user/src/com/google/gwt/user/client/rpc/StatusCodeException.java
@@ -23,6 +23,7 @@ */ public class StatusCodeException extends InvocationException { private final int statusCode; + private final String statusText; private final String encodedResponse; /** @@ -34,6 +35,21 @@ public StatusCodeException(int statusCode, String encodedResponse) { super(statusCode + " " + encodedResponse); this.statusCode = statusCode; + this.statusText = null; + this.encodedResponse = encodedResponse; + } + + /** + * Construct an exception with the given status code, status text and description. + * + * @param statusCode the HTTP status code to report + * @param statusText the HTTP status text to report + * @param encodedResponse the HTTP response message to report + */ + public StatusCodeException(int statusCode, String statusText, String encodedResponse) { + super(statusCode + " " + statusText + " " + encodedResponse); + this.statusCode = statusCode; + this.statusText = statusText; this.encodedResponse = encodedResponse; } @@ -50,4 +66,11 @@ public int getStatusCode() { return statusCode; } + + /** + * Returns the status text associated with the failed request. + */ + public String getStatusText() { + return statusText; + } } \ No newline at end of file
diff --git a/user/src/com/google/gwt/user/client/rpc/impl/RequestCallbackAdapter.java b/user/src/com/google/gwt/user/client/rpc/impl/RequestCallbackAdapter.java index 6e75a04..55143e3 100644 --- a/user/src/com/google/gwt/user/client/rpc/impl/RequestCallbackAdapter.java +++ b/user/src/com/google/gwt/user/client/rpc/impl/RequestCallbackAdapter.java
@@ -206,7 +206,7 @@ statsContext.bytesStat(methodName, encodedResponse.length(), "responseReceived")); if (statusCode != Response.SC_OK) { - caught = new StatusCodeException(statusCode, encodedResponse); + caught = new StatusCodeException(statusCode, response.getStatusText(), encodedResponse); } else if (encodedResponse == null) { // This can happen if the XHR is interrupted by the server dying caught = new InvocationException("No response payload from " + methodName);
diff --git a/user/test/com/google/gwt/user/client/rpc/RemoteServiceServletTest.java b/user/test/com/google/gwt/user/client/rpc/RemoteServiceServletTest.java index 880feef..593604d 100644 --- a/user/test/com/google/gwt/user/client/rpc/RemoteServiceServletTest.java +++ b/user/test/com/google/gwt/user/client/rpc/RemoteServiceServletTest.java
@@ -114,6 +114,7 @@ if (caught instanceof StatusCodeException) { assertEquals(Response.SC_NOT_FOUND, ((StatusCodeException) caught).getStatusCode()); + assertEquals("Not Found", ((StatusCodeException) caught).getStatusText()); finishTest(); } else { TestSetValidator.rethrowException(caught);