Fix generic handling of NameAlreadyUsedException in GerritCallback
GerritCallback identifies a NameAlreadyUsedException by checking the
exception message. Since commit 7125a01aa2
the exception message may now include the already used name. Because of
this the check in GerritCallback must be adapted. Make sure that the
already used name is included into the displayed error message.
Change-Id: I27813bca41c6218e7f6ce740b43a8d596c8763b5
Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
This commit is contained in:
@@ -18,13 +18,9 @@ package com.google.gerrit.common.errors;
|
|||||||
public class NameAlreadyUsedException extends Exception {
|
public class NameAlreadyUsedException extends Exception {
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
public static final String MESSAGE = "Name Already Used";
|
public static final String MESSAGE = "Name Already Used: ";
|
||||||
|
|
||||||
public NameAlreadyUsedException() {
|
|
||||||
super(MESSAGE);
|
|
||||||
}
|
|
||||||
|
|
||||||
public NameAlreadyUsedException(String name) {
|
public NameAlreadyUsedException(String name) {
|
||||||
super(MESSAGE + ": " + name);
|
super(MESSAGE + name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,7 +44,6 @@ public interface GerritConstants extends Constants {
|
|||||||
|
|
||||||
String notFoundTitle();
|
String notFoundTitle();
|
||||||
String notFoundBody();
|
String notFoundBody();
|
||||||
String nameAlreadyUsedBody();
|
|
||||||
String noSuchAccountTitle();
|
String noSuchAccountTitle();
|
||||||
|
|
||||||
String noSuchGroupTitle();
|
String noSuchGroupTitle();
|
||||||
|
|||||||
@@ -27,7 +27,6 @@ notSignedInBody = <b>Session Expired</b>\
|
|||||||
|
|
||||||
notFoundTitle = Not Found
|
notFoundTitle = Not Found
|
||||||
notFoundBody = The page you requested was not found, or you do not have permission to view this page.
|
notFoundBody = The page you requested was not found, or you do not have permission to view this page.
|
||||||
nameAlreadyUsedBody = The name is already in use.
|
|
||||||
noSuchAccountTitle = Code Review - Unknown User
|
noSuchAccountTitle = Code Review - Unknown User
|
||||||
|
|
||||||
noSuchGroupTitle = Code Review - Unknown Group
|
noSuchGroupTitle = Code Review - Unknown Group
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ public interface GerritMessages extends Messages {
|
|||||||
|
|
||||||
String noSuchAccountMessage(String who);
|
String noSuchAccountMessage(String who);
|
||||||
String noSuchGroupMessage(String who);
|
String noSuchGroupMessage(String who);
|
||||||
|
String nameAlreadyUsedBody(String alreadyUsedName);
|
||||||
|
|
||||||
String branchCreationFailed(String branchName, String error);
|
String branchCreationFailed(String branchName, String error);
|
||||||
String invalidBranchName(String branchName);
|
String invalidBranchName(String branchName);
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ poweredBy = Powered by <a href="http://code.google.com/p/gerrit/" target="_blank
|
|||||||
|
|
||||||
noSuchAccountMessage = {0} is not a registered user.
|
noSuchAccountMessage = {0} is not a registered user.
|
||||||
noSuchGroupMessage = Group {0} does not exist or is not visible to you.
|
noSuchGroupMessage = Group {0} does not exist or is not visible to you.
|
||||||
|
nameAlreadyUsedBody = The name {0} is already in use.
|
||||||
|
|
||||||
branchCreationFailed = Creating branch {0} failed. Error: {1}
|
branchCreationFailed = Creating branch {0} failed. Error: {1}
|
||||||
invalidBranchName = The branch name {0} is not valid.
|
invalidBranchName = The branch name {0} is not valid.
|
||||||
|
|||||||
@@ -54,7 +54,9 @@ public abstract class GerritCallback<T> implements
|
|||||||
d.center();
|
d.center();
|
||||||
|
|
||||||
} else if (isNameAlreadyUsed(caught)) {
|
} else if (isNameAlreadyUsed(caught)) {
|
||||||
new ErrorDialog(Gerrit.C.nameAlreadyUsedBody()).center();
|
final String msg = caught.getMessage();
|
||||||
|
final String alreadyUsedName = msg.substring(NameAlreadyUsedException.MESSAGE.length());
|
||||||
|
new ErrorDialog(Gerrit.M.nameAlreadyUsedBody(alreadyUsedName)).center();
|
||||||
|
|
||||||
} else if (isNoSuchGroup(caught)) {
|
} else if (isNoSuchGroup(caught)) {
|
||||||
final String msg = caught.getMessage();
|
final String msg = caught.getMessage();
|
||||||
@@ -101,7 +103,7 @@ public abstract class GerritCallback<T> implements
|
|||||||
|
|
||||||
private static boolean isNameAlreadyUsed(final Throwable caught) {
|
private static boolean isNameAlreadyUsed(final Throwable caught) {
|
||||||
return caught instanceof RemoteJsonException
|
return caught instanceof RemoteJsonException
|
||||||
&& caught.getMessage().equals(NameAlreadyUsedException.MESSAGE);
|
&& caught.getMessage().startsWith(NameAlreadyUsedException.MESSAGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isNoSuchGroup(final Throwable caught) {
|
private static boolean isNoSuchGroup(final Throwable caught) {
|
||||||
|
|||||||
Reference in New Issue
Block a user