2 Replies Latest reply on Aug 9, 2012 2:45 AM by ckrog

    Web app only detect “unexpected status code” in development mode?

    ckrog

      In chapter 2.4 in the Errai reference guide, an example is given how to detect errors caused when the server can’t be reached, or an unexpected status code was returned by the server.

       

      “Errai further provides a subject to subscribe to for handling global errors on the client (such as a disconnected server bus or an invalid response code) that occur outside a regular application message exchange. Subscribing to this subject is useful to detect errors early (e.g. due to failing heartbeat requests). A use case that comes to mind here is activating your application's offline mode.”

       

      So, I followed the example given, but I experienced that nothing happened when I closed down the jetty service hosted on a virtual machine.

      Digging into the code, I found that method onResponseReceived in ClientMessageBusImpl throws a TransportIOException if the status code is unexpected (which is what the documentation states)

       

      I configured my developer environment (IntelliJ) to use my own server in development mode instead of GWT's built-in Jetty instance (using the –noserver option).

      When up and running in development mode, I now closed the jetty service, and suddenly the default error dialog popped up with “…org.jboss.errai.bus.client.api.base.TransportIOException: unexpected response code: 12031…”.

       

      So it appears that the client do detect the server can’t be reached, or an unexpected status code was returned, but only in development mode.

      Nothing happens in production mode?

       

      Any ideas?

        • 1. Re: Web app only detect “unexpected status code” in development mode?
          csa

          It's intentional that the error popup only shows up in development mode. In production mode,  errors are logged to your browsers JavaScript console. But in any case, the ErrorCallback you specified should be notified. Global errors (like a wrong response code during long polling) are sent to a special subject on the bus: DefaultErrorCallback.CLIENT_ERROR_SUBJECT

          • 2. Re: Web app only detect “unexpected status code” in development mode?
            ckrog

            Thanks for your response.

            I have just made a second attempt, and the sample code below shows the alert dialog when I'm using Internet Explorer but NOT in Google Chrome…?

             

            @Override
            public void onModuleLoad() {
                    messageBus.addPostInitTask(new Runnable() {
                        @Override
                        public void run() {
                            ErraiBus.get().subscribe(DefaultErrorCallback.CLIENT_ERROR_SUBJECT, defaultErrorCallback);
                        }
                    });
              }
            

             

            private MessageCallback defaultErrorCallback = new MessageCallback() {
                    @Override
                    public void callback(Message message) {
                        try {
                            caught = message.get(Throwable.class, MessageParts.Throwable);
                            throw caught;
                        }
                        catch(TransportIOException e) {
                            // TODO: This dialog does not show up in Chrome. Do work in IE?!
                            Window.alert("server can't be reached or an unexpected status code was returned...");
                        }
                        catch (Throwable throwable) {
                            Window.alert("...should never happen :)");
                        }
                    }
                };