-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Give clients much more detailed errors #1168
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,49 @@ | ||
package com.firebase.ui.auth; | ||
|
||
import android.support.annotation.IntDef; | ||
|
||
import com.firebase.ui.auth.data.model.FirebaseUiException; | ||
|
||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
|
||
/** | ||
* Error codes retrieved from {@link IdpResponse#getErrorCode()}. | ||
* Error codes for failed sign-in attempts. | ||
*/ | ||
public final class ErrorCodes { | ||
/** | ||
* Sign in failed due to lack of network connection | ||
**/ | ||
public static final int NO_NETWORK = 10; | ||
* Valid codes that can be returned from {@link FirebaseUiException#getErrorCode()}. | ||
*/ | ||
@IntDef({ | ||
UNKNOWN_ERROR, | ||
NO_NETWORK, | ||
PLAY_SERVICES_UPDATE_CANCELLED, | ||
DEVELOPER_ERROR | ||
}) | ||
@Retention(RetentionPolicy.SOURCE) | ||
public @interface All {} | ||
|
||
/** | ||
* An unknown error has occurred. | ||
*/ | ||
public static final int UNKNOWN_ERROR = 0; | ||
|
||
/** | ||
* Sign in failed due to lack of network connection. | ||
*/ | ||
public static final int NO_NETWORK = 1; | ||
|
||
/** | ||
* A required update to Play Services was cancelled by the user. | ||
*/ | ||
public static final int PLAY_SERVICES_UPDATE_CANCELLED = 2; | ||
|
||
/** | ||
* An unknown error has occurred | ||
**/ | ||
public static final int UNKNOWN_ERROR = 20; | ||
* A sign-in operation couldn't be completed due to a developer error. | ||
*/ | ||
public static final int DEVELOPER_ERROR = 3; | ||
|
||
private ErrorCodes() { | ||
// no instance | ||
throw new AssertionError("No instance for you!"); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,46 @@ | ||
package com.firebase.ui.auth.data.model; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we move this to the root package or leave it as is? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this is |
||
|
||
import android.support.annotation.NonNull; | ||
import android.support.annotation.RestrictTo; | ||
|
||
import com.firebase.ui.auth.ErrorCodes; | ||
|
||
/** | ||
* Base class for all FirebaseUI exceptions. | ||
*/ | ||
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) | ||
public class FirebaseUiException extends Exception { | ||
private final int mErrorCode; | ||
|
||
public FirebaseUiException(int code) { | ||
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) | ||
public FirebaseUiException(@ErrorCodes.All int code) { | ||
mErrorCode = code; | ||
} | ||
|
||
public FirebaseUiException(int code, String message) { | ||
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) | ||
public FirebaseUiException(@ErrorCodes.All int code, @NonNull String message) { | ||
super(message); | ||
mErrorCode = code; | ||
} | ||
|
||
public FirebaseUiException(int code, String message, Throwable cause) { | ||
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) | ||
public FirebaseUiException(@ErrorCodes.All int code, | ||
@NonNull String message, | ||
@NonNull Throwable cause) { | ||
super(message, cause); | ||
mErrorCode = code; | ||
} | ||
|
||
public FirebaseUiException(int code, Throwable cause) { | ||
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) | ||
public FirebaseUiException(@ErrorCodes.All int code, @NonNull Throwable cause) { | ||
super(cause); | ||
mErrorCode = code; | ||
} | ||
|
||
/** | ||
* @return error code associated with this exception | ||
* @see com.firebase.ui.auth.ErrorCodes | ||
*/ | ||
@ErrorCodes.All | ||
public final int getErrorCode() { | ||
return mErrorCode; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,13 +14,15 @@ | |
|
||
package com.firebase.ui.auth.provider; | ||
|
||
import android.support.annotation.NonNull; | ||
|
||
import com.firebase.ui.auth.IdpResponse; | ||
|
||
public interface IdpProvider extends Provider { | ||
interface IdpCallback { | ||
void onSuccess(IdpResponse idpResponse); | ||
void onSuccess(@NonNull IdpResponse idpResponse); | ||
|
||
void onFailure(); | ||
void onFailure(@NonNull Exception e); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it possible that anyone was relying on this interface? If so this is a breaking change .... if this is meant to be internal let's annotate it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think so, or at least, I know we've broken it before without notice. I'll annotate it. |
||
} | ||
|
||
void setAuthenticationCallback(IdpCallback callback); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really happy with this name, any ideas?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe
Code
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SGTM,
ErrorCodes.Anything
feels weird, but yours makes more sense.