Revision: 10168
Author:   rj...@google.com
Date:     Mon May  9 10:55:18 2011
Log: Better error reporting. Also, move the proxy and request interfaces
to shared, where they belong — the servlet validates against them.

Review at http://gwt-code-reviews.appspot.com/1444801

Review by: jlaba...@google.com
http://code.google.com/p/google-web-toolkit/source/detail?r=10168

Added:
/trunk/samples/mobilewebapp/src/main/com/google/gwt/sample/mobilewebapp/shared/MobileWebAppRequestFactory.java /trunk/samples/mobilewebapp/src/main/com/google/gwt/sample/mobilewebapp/shared/TaskRequest.java
Deleted:
/trunk/samples/mobilewebapp/src/main/com/google/gwt/sample/mobilewebapp/client/MobileWebAppRequestFactory.java /trunk/samples/mobilewebapp/src/main/com/google/gwt/sample/mobilewebapp/client/TaskRequest.java
Modified:
/trunk/samples/mobilewebapp/src/main/com/google/gwt/sample/mobilewebapp/client/App.java /trunk/samples/mobilewebapp/src/main/com/google/gwt/sample/mobilewebapp/client/ClientFactory.java /trunk/samples/mobilewebapp/src/main/com/google/gwt/sample/mobilewebapp/client/ClientFactoryImpl.java /trunk/samples/mobilewebapp/src/main/com/google/gwt/sample/mobilewebapp/client/activity/TaskEditActivity.java

=======================================
--- /dev/null
+++ /trunk/samples/mobilewebapp/src/main/com/google/gwt/sample/mobilewebapp/shared/MobileWebAppRequestFactory.java Mon May 9 10:55:18 2011
@@ -0,0 +1,29 @@
+/*
+ * Copyright 2011 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.google.gwt.sample.mobilewebapp.shared;
+
+import com.google.web.bindery.requestfactory.shared.RequestFactory;
+
+/**
+ * Request factory for this app.
+ */
+public interface MobileWebAppRequestFactory extends RequestFactory {
+
+  /**
+   * Create a new {@link TaskRequest}.
+   */
+  TaskRequest taskRequest();
+}
=======================================
--- /dev/null
+++ /trunk/samples/mobilewebapp/src/main/com/google/gwt/sample/mobilewebapp/shared/TaskRequest.java Mon May 9 10:55:18 2011
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2011 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.google.gwt.sample.mobilewebapp.shared;
+
+import com.google.gwt.sample.mobilewebapp.server.domain.Task;
+import com.google.web.bindery.requestfactory.shared.InstanceRequest;
+import com.google.web.bindery.requestfactory.shared.Request;
+import com.google.web.bindery.requestfactory.shared.RequestContext;
+import com.google.web.bindery.requestfactory.shared.Service;
+
+import java.util.List;
+
+/**
+ * Remote request for {@link Task}.
+ */
+@Service(Task.class)
+public interface TaskRequest extends RequestContext {
+
+  /**
+   * Create a {@link Request} for all tasks.
+   *
+   * @return a {@link Request}
+   */
+  Request<List<TaskProxy>> findAllTasks();
+
+  /**
+   * Create a {@link Request} to find a Task by id.
+   *
+   * @param id the task id
+   * @return a {@link Request}
+   */
+  Request<TaskProxy> findTask(Long id);
+
+  /**
+   * Persist a Task instance in the datastore.
+   *
+   * @return an {@link InstanceRequest}
+   */
+  InstanceRequest<TaskProxy, Void> persist();
+
+  /**
+   * Remove a Task instance from the datastore.
+   *
+   * @return an {@link InstanceRequest}
+   */
+  InstanceRequest<TaskProxy, Void> remove();
+}
=======================================
--- /trunk/samples/mobilewebapp/src/main/com/google/gwt/sample/mobilewebapp/client/MobileWebAppRequestFactory.java Tue May 3 10:43:13 2011
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Copyright 2011 Google Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-package com.google.gwt.sample.mobilewebapp.client;
-
-import com.google.web.bindery.requestfactory.shared.RequestFactory;
-
-/**
- * Request factory for this app.
- */
-public interface MobileWebAppRequestFactory extends RequestFactory {
-
-  /**
-   * Create a new {@link TaskRequest}.
-   */
-  TaskRequest taskRequest();
-}
=======================================
--- /trunk/samples/mobilewebapp/src/main/com/google/gwt/sample/mobilewebapp/client/TaskRequest.java Tue May 3 10:43:13 2011
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Copyright 2011 Google Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-package com.google.gwt.sample.mobilewebapp.client;
-
-import com.google.gwt.sample.mobilewebapp.server.domain.Task;
-import com.google.gwt.sample.mobilewebapp.shared.TaskProxy;
-import com.google.web.bindery.requestfactory.shared.InstanceRequest;
-import com.google.web.bindery.requestfactory.shared.Request;
-import com.google.web.bindery.requestfactory.shared.RequestContext;
-import com.google.web.bindery.requestfactory.shared.Service;
-
-import java.util.List;
-
-/**
- * Remote request for {@link Task}.
- */
-@Service(Task.class)
-public interface TaskRequest extends RequestContext {
-
-  /**
-   * Create a {@link Request} for all tasks.
-   *
-   * @return a {@link Request}
-   */
-  Request<List<TaskProxy>> findAllTasks();
-
-  /**
-   * Create a {@link Request} to find a Task by id.
-   *
-   * @param id the task id
-   * @return a {@link Request}
-   */
-  Request<TaskProxy> findTask(Long id);
-
-  /**
-   * Persist a Task instance in the datastore.
-   *
-   * @return an {@link InstanceRequest}
-   */
-  InstanceRequest<TaskProxy, Void> persist();
-
-  /**
-   * Remove a Task instance from the datastore.
-   *
-   * @return an {@link InstanceRequest}
-   */
-  InstanceRequest<TaskProxy, Void> remove();
-}
=======================================
--- /trunk/samples/mobilewebapp/src/main/com/google/gwt/sample/mobilewebapp/client/App.java Mon May 9 08:12:52 2011 +++ /trunk/samples/mobilewebapp/src/main/com/google/gwt/sample/mobilewebapp/client/App.java Mon May 9 10:55:18 2011
@@ -15,6 +15,8 @@
  */
 package com.google.gwt.sample.mobilewebapp.client;

+import com.google.gwt.core.client.GWT;
+import com.google.gwt.core.client.GWT.UncaughtExceptionHandler;
 import com.google.gwt.event.shared.EventBus;
 import com.google.gwt.place.shared.Place;
 import com.google.gwt.place.shared.PlaceChangeEvent;
@@ -24,7 +26,9 @@
import com.google.gwt.sample.mobilewebapp.client.place.AppPlaceHistoryMapper;
 import com.google.gwt.sample.mobilewebapp.client.place.TaskListPlace;
 import com.google.gwt.storage.client.Storage;
+import com.google.gwt.user.client.Window;
 import com.google.gwt.user.client.ui.HasWidgets;
+import com.google.web.bindery.event.shared.UmbrellaException;

 /**
  * The heart of the applicaiton, mainly concerned with bootstrapping.
@@ -53,7 +57,7 @@
   private final AppPlaceHistoryMapper historyMapper;

   private final PlaceHistoryHandler historyHandler;
-
+
private final ReloadOnAuthenticationFailure reloadOnAuthenticationFailure;

public App(Storage storage, EventBus eventBus, PlaceController placeController,
@@ -77,6 +81,17 @@
   public void run(HasWidgets.ForIsWidget parentView) {
     parentView.add(shell);

+    GWT.setUncaughtExceptionHandler(new UncaughtExceptionHandler() {
+      @Override
+      public void onUncaughtException(Throwable e) {
+        while (e instanceof UmbrellaException) {
+          e = ((UmbrellaException)e).getCauses().iterator().next();
+        }
+        Window.alert("An unexpected error occurred: " + e.getMessage());
+        placeController.goTo(new TaskListPlace(false));
+      }
+    });
+
     // Check for authentication failures or mismatches
     reloadOnAuthenticationFailure.register(eventBus);

=======================================
--- /trunk/samples/mobilewebapp/src/main/com/google/gwt/sample/mobilewebapp/client/ClientFactory.java Mon May 9 09:40:33 2011 +++ /trunk/samples/mobilewebapp/src/main/com/google/gwt/sample/mobilewebapp/client/ClientFactory.java Mon May 9 10:55:18 2011
@@ -21,6 +21,7 @@
 import com.google.gwt.sample.mobilewebapp.client.activity.TaskListView;
 import com.google.gwt.sample.mobilewebapp.client.activity.TaskReadView;
 import com.google.gwt.storage.client.Storage;
+import com.google.gwt.sample.mobilewebapp.shared.MobileWebAppRequestFactory;

 /**
  * The factory responsible for instantiating everything interesting in this
=======================================
--- /trunk/samples/mobilewebapp/src/main/com/google/gwt/sample/mobilewebapp/client/ClientFactoryImpl.java Mon May 9 10:25:15 2011 +++ /trunk/samples/mobilewebapp/src/main/com/google/gwt/sample/mobilewebapp/client/ClientFactoryImpl.java Mon May 9 10:55:18 2011
@@ -34,6 +34,7 @@
import com.google.gwt.sample.mobilewebapp.client.desktop.DesktopTaskReadView; import com.google.gwt.sample.mobilewebapp.client.desktop.MobileWebAppShellDesktop; import com.google.gwt.sample.mobilewebapp.client.place.AppPlaceHistoryMapper; +import com.google.gwt.sample.mobilewebapp.shared.MobileWebAppRequestFactory;
 import com.google.gwt.storage.client.Storage;
 import com.google.gwt.user.client.Window;
 import com.google.web.bindery.requestfactory.shared.RequestTransport;
=======================================
--- /trunk/samples/mobilewebapp/src/main/com/google/gwt/sample/mobilewebapp/client/activity/TaskEditActivity.java Mon May 9 09:40:33 2011 +++ /trunk/samples/mobilewebapp/src/main/com/google/gwt/sample/mobilewebapp/client/activity/TaskEditActivity.java Mon May 9 10:55:18 2011
@@ -18,11 +18,11 @@
 import com.google.gwt.activity.shared.AbstractActivity;
 import com.google.gwt.event.shared.EventBus;
 import com.google.gwt.sample.mobilewebapp.client.ClientFactory;
-import com.google.gwt.sample.mobilewebapp.client.TaskRequest;
 import com.google.gwt.sample.mobilewebapp.client.place.TaskEditPlace;
 import com.google.gwt.sample.mobilewebapp.client.place.TaskListPlace;
 import com.google.gwt.sample.mobilewebapp.client.ui.SoundEffects;
 import com.google.gwt.sample.mobilewebapp.shared.TaskProxy;
+import com.google.gwt.sample.mobilewebapp.shared.TaskRequest;
 import com.google.gwt.user.client.Window;
 import com.google.gwt.user.client.ui.AcceptsOneWidget;
 import com.google.web.bindery.requestfactory.shared.Receiver;
@@ -129,13 +129,6 @@
public void onConstraintViolation(Set<ConstraintViolation<?>> violations) {
         handleConstraintViolations(violations);
       }
-
-      @Override
-      public void onFailure(ServerFailure error) {
- Window.alert("An error occurred on the server while saving this task."
-            + " Please try saving the task again.");
-        doCancelTask();
-      }

       @Override
       public void onSuccess(Void response) {
@@ -176,13 +169,6 @@
         // Load the existing task.
clientFactory.getRequestFactory().taskRequest().findTask(this.taskId).fire(
             new Receiver<TaskProxy>() {
-              @Override
-              public void onFailure(ServerFailure error) {
- Window.alert("An error occurred on the server while loading this task." - + " Please select a different task from the task list.");
-                doCancelTask();
-              }
-
               @Override
               public void onSuccess(TaskProxy response) {
                 // Early exit if this activity has already been cancelled.
@@ -234,8 +220,8 @@
         new Receiver<Void>() {
           @Override
           public void onFailure(ServerFailure error) {
- Window.alert("An error occurred on the server while deleting this task."
-                + " Please try deleting it again.");
+ Window.alert("An error occurred on the server while deleting this task: \"."
+                + error.getMessage() + "\".");
           }

           @Override
@@ -292,13 +278,6 @@
       editView.setLocked(true);
clientFactory.getRequestFactory().taskRequest().findTask(this.taskId).fire(
           new Receiver<TaskProxy>() {
-            @Override
-            public void onFailure(ServerFailure error) {
- Window.alert("An error occurred on the server while loading this task."
-                  + " Please select a different task from the task list.");
-              doCancelTask();
-            }
-
             @Override
             public void onSuccess(TaskProxy response) {
               // Early exit if this activity has already been cancelled.

--
http://groups.google.com/group/Google-Web-Toolkit-Contributors

Reply via email to