Merge "Return a message to the user if request fails due to LOCK_FAILURE"
This commit is contained in:
@@ -25,6 +25,11 @@ import org.eclipse.jgit.lib.RefUpdate;
|
|||||||
* a retry of the failed operation.
|
* a retry of the failed operation.
|
||||||
*/
|
*/
|
||||||
public class ExceptionHookImpl implements ExceptionHook {
|
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
|
@Override
|
||||||
public boolean shouldRetry(Throwable throwable) {
|
public boolean shouldRetry(Throwable throwable) {
|
||||||
return isLockFailure(throwable);
|
return isLockFailure(throwable);
|
||||||
@@ -38,6 +43,14 @@ public class ExceptionHookImpl implements ExceptionHook {
|
|||||||
return Optional.empty();
|
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) {
|
private static boolean isLockFailure(Throwable throwable) {
|
||||||
return isMatching(throwable, t -> t instanceof LockFailureException);
|
return isMatching(throwable, t -> t instanceof LockFailureException);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user