Commit 03613afa authored by Boris Sazonov's avatar Boris Sazonov Committed by Commit Bot

[Android] Revise AuthException

This CL makes several changes to AuthException and its users:
1. Add second constructor that accepts message that can be used to report info
   about context that caused auth failure.
2. Use newly-added constructor to report authTokenScope that caused
   GoogleAuthException.
3. Add AuthException.TRANSIENT and AuthException.NONTRANSIENT constants to use
   in AuthException constructors.

Bug: 741883
Change-Id: I6448ef2e4ecc66a885a0d3dc21f8665f678689ca
Reviewed-on: https://chromium-review.googlesource.com/574541Reviewed-by: default avatarMihai Sardarescu <msarda@chromium.org>
Commit-Queue: Boris Sazonov <bsazonov@chromium.org>
Cr-Commit-Position: refs/heads/master@{#487428}
parent 5eab649a
...@@ -9,15 +9,31 @@ package org.chromium.components.signin; ...@@ -9,15 +9,31 @@ package org.chromium.components.signin;
* It is used for passing information that is useful for better handling of errors. * It is used for passing information that is useful for better handling of errors.
*/ */
public class AuthException extends Exception { public class AuthException extends Exception {
public static final boolean TRANSIENT = true;
public static final boolean NONTRANSIENT = false;
private final boolean mIsTransientError; private final boolean mIsTransientError;
/** /**
* A simple constructor that stores all the error handling information and makes it available to * Wraps exception that caused auth failure along with transience flag.
* the handler. * @param isTransientError Whether the error is transient and we can retry.
* Use {@link #TRANSIENT} and {@link #NONTRANSIENT} for readability.
* @param cause Exception that caused auth failure.
*/
public AuthException(boolean isTransientError, Exception cause) {
super(cause);
mIsTransientError = isTransientError;
}
/**
* Wraps exception that caused auth failure along with transience flag and message.
* @param isTransientError Whether the error is transient and we can retry. * @param isTransientError Whether the error is transient and we can retry.
* Use {@link #TRANSIENT} and {@link #NONTRANSIENT} for readability.
* @param message Message describing context in which auth failure happened.
* @param cause Exception that caused auth failure.
*/ */
public AuthException(boolean isTransientError, Exception exception) { public AuthException(boolean isTransientError, String message, Exception cause) {
super(exception); super(message, cause);
mIsTransientError = isTransientError; mIsTransientError = isTransientError;
} }
......
...@@ -102,10 +102,10 @@ public class SystemAccountManagerDelegate implements AccountManagerDelegate { ...@@ -102,10 +102,10 @@ public class SystemAccountManagerDelegate implements AccountManagerDelegate {
} catch (GoogleAuthException ex) { } catch (GoogleAuthException ex) {
// This case includes a UserRecoverableNotifiedException, but most clients will have // This case includes a UserRecoverableNotifiedException, but most clients will have
// their own retry mechanism anyway. // their own retry mechanism anyway.
// TODO(bauerb): Investigate integrating the callback with ConnectionRetry. throw new AuthException(AuthException.NONTRANSIENT,
throw new AuthException(false /* isTransientError */, ex); "Error while getting token for scope '" + authTokenScope + "'", ex);
} catch (IOException ex) { } catch (IOException ex) {
throw new AuthException(true /* isTransientError */, ex); throw new AuthException(AuthException.TRANSIENT, ex);
} }
} }
...@@ -114,11 +114,11 @@ public class SystemAccountManagerDelegate implements AccountManagerDelegate { ...@@ -114,11 +114,11 @@ public class SystemAccountManagerDelegate implements AccountManagerDelegate {
try { try {
GoogleAuthUtil.clearToken(ContextUtils.getApplicationContext(), authToken); GoogleAuthUtil.clearToken(ContextUtils.getApplicationContext(), authToken);
} catch (GooglePlayServicesAvailabilityException ex) { } catch (GooglePlayServicesAvailabilityException ex) {
throw new AuthException(false /* isTransientError */, ex); throw new AuthException(AuthException.NONTRANSIENT, ex);
} catch (GoogleAuthException ex) { } catch (GoogleAuthException ex) {
throw new AuthException(false /* isTransientError */, ex); throw new AuthException(AuthException.NONTRANSIENT, ex);
} catch (IOException ex) { } catch (IOException ex) {
throw new AuthException(true /* isTransientError */, ex); throw new AuthException(AuthException.TRANSIENT, ex);
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment