Merge "Return a message to the user if request fails due to LOCK_FAILURE"

This commit is contained in:
Edwin Kempin
2019-11-26 11:56:36 +00:00
committed by Gerrit Code Review

View File

@@ -25,6 +25,11 @@ import org.eclipse.jgit.lib.RefUpdate;
* a retry of the failed operation.
*/
public class ExceptionHookImpl implements ExceptionHook {
private static final String LOCK_FAILURE_USER_MESSAGE =
"Updating a ref failed with LOCK_FAILURE.\n"
+ "This may be a temporary issue due to concurrent updates.\n"
+ "Please retry later.";
@Override
public boolean shouldRetry(Throwable throwable) {
return isLockFailure(throwable);
@@ -38,6 +43,14 @@ public class ExceptionHookImpl implements ExceptionHook {
return Optional.empty();
}
@Override
public Optional<String> getUserMessage(Throwable throwable) {
if (isLockFailure(throwable)) {
return Optional.of(LOCK_FAILURE_USER_MESSAGE);
}
return Optional.empty();
}
private static boolean isLockFailure(Throwable throwable) {
return isMatching(throwable, t -> t instanceof LockFailureException);
}