From 54ea978b51cddd53a5a517ce872d45d2aa998878 Mon Sep 17 00:00:00 2001
From: buczekp <buczekp>
Date: Tue, 19 Jul 2011 09:43:12 +0000
Subject: [PATCH] [LMS-2336] better error message handling

SVN: 22201
---
 .../web/client/application/AbstractAsyncCallback.java    | 9 +++++----
 .../client/web/client/application/util/GWTUtils.java     | 4 ++--
 .../generic/client/web/server/CommonClientService.java   | 9 ++++++++-
 3 files changed, 15 insertions(+), 7 deletions(-)

diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/AbstractAsyncCallback.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/AbstractAsyncCallback.java
index b13f39b0854..da2c68c2da0 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/AbstractAsyncCallback.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/AbstractAsyncCallback.java
@@ -70,20 +70,21 @@ public abstract class AbstractAsyncCallback<T> implements AsyncCallback<T>
                             final AbstractAsyncCallback<Object> callback,
                             final String failureMessage, final Throwable throwable)
                     {
-
+                        String message = GWTUtils.translateToHtmlLineBreaks(failureMessage);
                         if (throwable instanceof UserFailureException)
                         {
                             UserFailureException userException = (UserFailureException) throwable;
-                            String details = userException.getDetails();
+                            String details =
+                                    GWTUtils.translateToHtmlLineBreaks(userException.getDetails());
                             if (details != null)
                             {
                                 GWTUtils.createErrorMessageWithDetailsDialog(messageProvider,
-                                        failureMessage, details).show();
+                                        message, details).show();
                                 return;
                             }
                         }
                         // no details - show simple error message box
-                        MessageBox.alert("Error", failureMessage, null);
+                        MessageBox.alert("Error", message, null);
                     }
 
                 };
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/util/GWTUtils.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/util/GWTUtils.java
index 936db0dfabb..bd7c3df8080 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/util/GWTUtils.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/util/GWTUtils.java
@@ -313,9 +313,9 @@ public final class GWTUtils
         component.setToolTip(config);
     }
 
-    public static String translateToHtmlLineBreaks(String text)
+    public static String translateToHtmlLineBreaks(String textOrNull)
     {
-        return text.replace("\n", "<br>");
+        return textOrNull != null ? textOrNull.replace("\n", "<br>") : null;
     }
 
     /** @return specified model from the list if it's found, null otherwise */
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/CommonClientService.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/CommonClientService.java
index c0eabd56c18..7dc1af66d71 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/CommonClientService.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/CommonClientService.java
@@ -2218,7 +2218,14 @@ public final class CommonClientService extends AbstractClientService implements
     public void revertDeletions(List<TechId> deletionIds)
             throws ch.systemsx.cisd.openbis.generic.client.web.client.exception.UserFailureException
     {
-        commonServer.revertDeletions(getSessionToken(), deletionIds);
+        try
+        {
+            commonServer.revertDeletions(getSessionToken(), deletionIds);
+        } catch (UserFailureException ex)
+        {
+            throw new ch.systemsx.cisd.openbis.generic.client.web.client.exception.UserFailureException(
+                    ex.getMessage() + "\n\nTry reverting the dependent deletion first.");
+        }
     }
 
     public void deletePermanently(List<TechId> deletionIds)
-- 
GitLab