Display proper error message if non-existing/non-visible group is browsed

Browsing a group that does not exist or which is not visible for the
user fails and Gerrit shows the error message "Application Error,
Server Error, <group-id>". Since this error message looks like
something severe had gone wrong in Gerrit, this change implements
that now a proper error message is displayed in this case.
This fix is especially important since bug 797 allows a user to see
access rights for a group that is not visible to him and a link to
browse the group is provided which results in the error above if the
user clicks on it.

Bug: issue 804
Change-Id: Ieebdfd11cdea99e561bce49d09e83fbb10ada307
Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
This commit is contained in:
Edwin Kempin
2011-03-10 14:52:05 +01:00
parent 0ff5ff0112
commit ff2438231f
12 changed files with 32 additions and 8 deletions

View File

@@ -21,6 +21,7 @@ import com.google.gerrit.common.errors.InactiveAccountException;
import com.google.gerrit.common.errors.NameAlreadyUsedException;
import com.google.gerrit.common.errors.NoSuchAccountException;
import com.google.gerrit.common.errors.NoSuchEntityException;
import com.google.gerrit.common.errors.NoSuchGroupException;
import com.google.gerrit.common.errors.NotSignedInException;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
@@ -51,6 +52,13 @@ public abstract class GerritCallback<T> implements AsyncCallback<T> {
} else if (isNameAlreadyUsed(caught)) {
new ErrorDialog(Gerrit.C.nameAlreadyUsedBody()).center();
} else if (isNoSuchGroup(caught)) {
final String msg = caught.getMessage();
final String group = msg.substring(NoSuchGroupException.MESSAGE.length());
final ErrorDialog d = new ErrorDialog(Gerrit.M.noSuchGroupMessage(group));
d.setText(Gerrit.C.noSuchGroupTitle());
d.center();
} else if (caught instanceof ServerUnavailableException) {
new ErrorDialog(RpcConstants.C.errorServerUnavailable()).center();
@@ -89,4 +97,9 @@ public abstract class GerritCallback<T> implements AsyncCallback<T> {
return caught instanceof RemoteJsonException
&& caught.getMessage().equals(NameAlreadyUsedException.MESSAGE);
}
private static boolean isNoSuchGroup(final Throwable caught) {
return caught instanceof RemoteJsonException
&& caught.getMessage().startsWith(NoSuchGroupException.MESSAGE);
}
}