Take the 2-minute tour ×

I'm sending an HTTP request with RequestBuilder.send(). I would expect to see successful responses come back in onResponseReceived(), and errors come back in onError(). But that's not what I'm seeing. GWT calls onResponseReceived() regardless of success or failure.

Does anyone know what I should really expect? Do you have any information that would help me detect and report errors better?

Here's some sample code:

            builder.sendRequest(null, new RequestCallback() {
            public void onResponseReceived(Request request, Response response) {
                Header[] debugHeaders = response.getHeaders();
                String debugHeaders1 = response.getHeadersAsString();
                int debugStatusCode = response.getStatusCode();
                String debugStatusText = response.getStatusText();
                String debugText = response.getText();
            public void onError(Request request, Throwable exception) {

I can force an error on my computer by disabling the Wi-Fi. In that case onResponse() is called. getHeaders() returns an array of length 1, with the only entry set to null. getHeadersAsString returns "". getStatusCode returns 0. getStatusText() returns "". getText() returns "".

If this is always the case, I can look for that in my code. However, I expect that different browsers, different errors, etc, will cause a different result. Is there any good way to always detect an error?

(As long as there are no HTTP problems, my code works fine.)

share|improve this question
What if you throw a RuntimeException in the server code of that service call ? –  thibaultd Aug 31 '13 at 7:51
I'm referring to the case where I can't get to the server at all. –  Trade-Ideas Philip Aug 31 '13 at 17:05

2 Answers 2

up vote 2 down vote accepted

This the expected behavior; see comments in: https://code.google.com/p/google-web-toolkit/issues/detail?id=2858

share|improve this answer
Wow, that's really buried in there. I'm glad to see I'm not the only one who having trouble finding this "feature" in the documentation. It seems that calling onResponseReceived() and returning 0 from getStatusCode() is a common way for GWT to report that a response was not received. –  Trade-Ideas Philip Aug 31 '13 at 17:19
It's a common way for the underlying XMLHttpRequest, and RequestBuilder simply doesn't surface any differently. –  Thomas Broyer Aug 31 '13 at 21:53

According to documentation onResponseReceived is called in both cases (success or not). I got the same on old browsers when my browser tried to go to download something and the prev. http request was not completed. So maybe try to wait untill the response is completed, maybe try to add some 200 msec. delay somewhere.

In my application i ignore when status code is 0.

share|improve this answer
I'm looking at the status code, as you suggest, and that seems to work. –  Trade-Ideas Philip Aug 31 '13 at 17:13

Your Answer


