Display sign-out dialog when adding reviewers
Adding reviewers overrides the GerritCallback onFailure event handler and doesn't check the normal cases for a signed out user. Since the error handling should display a message below the field and not a dialog, we can't use the parent class, but we can use the helper methods to at least determine when to display the signed-out dialog. Change-Id: Ie25efc014cc106373664b3ddf26122d4c73c7928
This commit is contained in:
		@@ -17,6 +17,7 @@ package com.google.gerrit.client.change;
 | 
			
		||||
import com.google.gerrit.client.ConfirmationCallback;
 | 
			
		||||
import com.google.gerrit.client.ConfirmationDialog;
 | 
			
		||||
import com.google.gerrit.client.Gerrit;
 | 
			
		||||
import com.google.gerrit.client.NotSignedInDialog;
 | 
			
		||||
import com.google.gerrit.client.changes.ChangeApi;
 | 
			
		||||
import com.google.gerrit.client.changes.Util;
 | 
			
		||||
import com.google.gerrit.client.info.AccountInfo;
 | 
			
		||||
@@ -177,10 +178,14 @@ public class Reviewers extends Composite {
 | 
			
		||||
 | 
			
		||||
          @Override
 | 
			
		||||
          public void onFailure(Throwable err) {
 | 
			
		||||
            UIObject.setVisible(error, true);
 | 
			
		||||
            error.setInnerText(err instanceof StatusCodeException
 | 
			
		||||
                ? ((StatusCodeException) err).getEncodedResponse()
 | 
			
		||||
                : err.getMessage());
 | 
			
		||||
            if (isSigninFailure(err)) {
 | 
			
		||||
              new NotSignedInDialog().center();
 | 
			
		||||
            } else {
 | 
			
		||||
              UIObject.setVisible(error, true);
 | 
			
		||||
              error.setInnerText(err instanceof StatusCodeException
 | 
			
		||||
                  ? ((StatusCodeException) err).getEncodedResponse()
 | 
			
		||||
                  : err.getMessage());
 | 
			
		||||
            }
 | 
			
		||||
          }
 | 
			
		||||
        });
 | 
			
		||||
  }
 | 
			
		||||
 
 | 
			
		||||
@@ -38,15 +38,10 @@ public abstract class GerritCallback<T> implements
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public static void showFailure(Throwable caught) {
 | 
			
		||||
    if (isNotSignedIn(caught) || isInvalidXSRF(caught)) {
 | 
			
		||||
    if (isSigninFailure(caught)) {
 | 
			
		||||
      new NotSignedInDialog().center();
 | 
			
		||||
 | 
			
		||||
    } else if (isNoSuchEntity(caught)) {
 | 
			
		||||
      if (Gerrit.isSignedIn()) {
 | 
			
		||||
        new ErrorDialog(Gerrit.C.notFoundBody()).center();
 | 
			
		||||
      } else {
 | 
			
		||||
        new NotSignedInDialog().center();
 | 
			
		||||
      }
 | 
			
		||||
      new ErrorDialog(Gerrit.C.notFoundBody()).center();
 | 
			
		||||
    } else if (isInactiveAccount(caught)) {
 | 
			
		||||
      new ErrorDialog(Gerrit.C.inactiveAccountBody()).center();
 | 
			
		||||
 | 
			
		||||
@@ -77,12 +72,20 @@ public abstract class GerritCallback<T> implements
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private static boolean isInvalidXSRF(final Throwable caught) {
 | 
			
		||||
  public static boolean isSigninFailure(Throwable caught) {
 | 
			
		||||
    if (isNotSignedIn(caught) || isInvalidXSRF(caught) ||
 | 
			
		||||
        (isNoSuchEntity(caught) && !Gerrit.isSignedIn())) {
 | 
			
		||||
      return true;
 | 
			
		||||
    }
 | 
			
		||||
    return false;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  protected static boolean isInvalidXSRF(final Throwable caught) {
 | 
			
		||||
    return caught instanceof InvocationException
 | 
			
		||||
        && caught.getMessage().equals(JsonConstants.ERROR_INVALID_XSRF);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private static boolean isNotSignedIn(Throwable caught) {
 | 
			
		||||
  protected static boolean isNotSignedIn(Throwable caught) {
 | 
			
		||||
    return RestApi.isNotSignedIn(caught)
 | 
			
		||||
        || (caught instanceof RemoteJsonException
 | 
			
		||||
           && caught.getMessage().equals(NotSignedInException.MESSAGE));
 | 
			
		||||
@@ -99,17 +102,17 @@ public abstract class GerritCallback<T> implements
 | 
			
		||||
        && caught.getMessage().startsWith(InactiveAccountException.MESSAGE);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private static boolean isNoSuchAccount(final Throwable caught) {
 | 
			
		||||
  protected static boolean isNoSuchAccount(final Throwable caught) {
 | 
			
		||||
    return caught instanceof RemoteJsonException
 | 
			
		||||
        && caught.getMessage().startsWith(NoSuchAccountException.MESSAGE);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private static boolean isNameAlreadyUsed(final Throwable caught) {
 | 
			
		||||
  protected static boolean isNameAlreadyUsed(final Throwable caught) {
 | 
			
		||||
    return caught instanceof RemoteJsonException
 | 
			
		||||
        && caught.getMessage().startsWith(NameAlreadyUsedException.MESSAGE);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private static boolean isNoSuchGroup(final Throwable caught) {
 | 
			
		||||
  protected static boolean isNoSuchGroup(final Throwable caught) {
 | 
			
		||||
    return caught instanceof RemoteJsonException
 | 
			
		||||
    && caught.getMessage().startsWith(NoSuchGroupException.MESSAGE);
 | 
			
		||||
  }
 | 
			
		||||
 
 | 
			
		||||
@@ -44,12 +44,10 @@ public abstract class ScreenLoadCallback<T> extends GerritCallback<T> {
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
  public void onFailure(final Throwable caught) {
 | 
			
		||||
    if (isNoSuchEntity(caught)) {
 | 
			
		||||
      if (Gerrit.isSignedIn()) {
 | 
			
		||||
        Gerrit.display(screen.getToken(), new NotFoundScreen());
 | 
			
		||||
      } else {
 | 
			
		||||
        new NotSignedInDialog().center();
 | 
			
		||||
      }
 | 
			
		||||
    if (isSigninFailure(caught)) {
 | 
			
		||||
      new NotSignedInDialog().center();
 | 
			
		||||
    } else if (isNoSuchEntity(caught)) {
 | 
			
		||||
      Gerrit.display(screen.getToken(), new NotFoundScreen());
 | 
			
		||||
    } else {
 | 
			
		||||
      super.onFailure(caught);
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user