Error handling
The Android SDK provides error logging.
Interaction with the Android SDK can result in errors. All error classes have the pattern name Onegini_TYPE_Error
where _TYPE_
s particular scenario with different set of error which can occur. For example the OneginiAuthenticationHandler
in its onError
method returns the OneginiAuthenticationError
, which specifies that only the following errors can occur:
- GENERAL_ERROR,
- NETWORK_CONNECTIVITY_PROBLEM,
- SERVER_NOT_REACHABLE,
- DEVICE_DEREGISTERED,
- CONFIGURATION_ERROR,
- USER_DEREGISTERED,
- OUTDATED_APP,
- OUTDATED_OS,
- ACTION_CANCELED,
- ACTION_ALREADY_IN_PROGRESS,
- AUTHENTICATOR_NOT_REGISTERED,
- INVALID_AUTHENTICATOR,
- CUSTOM_AUTHENTICATOR_FAILURE,
- CUSTOM_AUTHENTICATION_DISABLED,
- AUTHENTICATOR_DEREGISTERED,
- DATA_STORAGE_NOT_AVAILABLE.
You can access a more comprehensive error description by calling the getMessage()
method on OneginiError
objects. OneginiError
also contains an instance of OneginiErrorDetails
that can be accessed by calling getErrorDetails()
.
/**
* An interface to return additional error details when needed.
*/
public interface OneginiErrorDetails {
/**
* Returns the {@link CustomInfo} object if the error was caused by custom authenticator.
* @return instance of {@link CustomInfo} or null
*/
CustomInfo getCustomInfo();
/**
* Returns the {@link UserProfile} object if the profile was deregistered as an effect of the error.
* @return instance of {@link UserProfile} or null
*/
UserProfile getUserProfile();
/**
* Returns the {@link OneginiAuthenticator} object of the authenticator was deregistered as an effect of the error.
* @return instance of {@link OneginiAuthenticator} or null
*/
OneginiAuthenticator getAuthenticator();
}
For some errors, additional information can be received using this interface. For example, in case of failed authentication with a custom authenticator, if the error was returned by the custom authenticator script on the server side, then the OneginiErrorDetails#getCustomInfo
will return the error details provided by the script (error code and data).
Error codes
Every error includes a code. There are two ranges of error codes:
-
From 9000 to 10.000: These codes are reserved for errors that you should show to your users. For example, they indicate that there was a connection problem with the IDAAS-core or that the app version that is used by the user is outdated.
-
10.000 and higher: These are errors that usually will not happen or might indicate that there is a misconfiguration in the IDAAS-core.
The OneginiAuthenticationError
class contains the following errors:
public class OneginiAuthenticationError implements OneginiError {
public static final int GENERAL_ERROR = 10000;
public static final int NETWORK_CONNECTIVITY_PROBLEM = 9000;
public static final int SERVER_NOT_REACHABLE = 9001;
public static final int DEVICE_DEREGISTERED = 9002;
public static final int CONFIGURATION_ERROR = 10001;
public static final int USER_DEREGISTERED = 9003;
public static final int OUTDATED_APP = 9004;
public static final int OUTDATED_OS = 9005;
public static final int ACTION_CANCELED = 9006;
public static final int ACTION_ALREADY_IN_PROGRESS = 9007;
public static final int AUTHENTICATOR_NOT_REGISTERED = 10_007;
public static final int INVALID_AUTHENTICATOR = 9015;
public static final int CUSTOM_AUTHENTICATOR_FAILURE = 9027;
public static final int CUSTOM_AUTHENTICATION_DISABLED = 10_017;
public static final int AUTHENTICATOR_DEREGISTERED = 9022;
public static final int DATA_STORAGE_NOT_AVAILABLE = 9024;
// ...
}
Error handling
You can implement specific error handling behavior or combine other errors into sets for more generic error handling. It is not required to handle all errors that are returned by the Android SDK.
Example code - handling user registration errors
private void registerUser() {
final OneginiClient oneginiClient = OneginiSDK.getOneginiClient(this);
oneginiClient.getUserClient().registerUser(null, Constants.DEFAULT_SCOPES, new OneginiRegistrationHandler() {
@Override
public void onSuccess(final UserProfile userProfile) {
PinActivity.setRemainingFailedAttempts(0);
registeredProfile = userProfile;
userProfileDebugText.setText(userProfile.getProfileId());
askForProfileName();
}
@Override
public void onError(final OneginiRegistrationError oneginiRegistrationError) {
handleRegistrationErrors(oneginiRegistrationError);
}
});
}
private void handleRegistrationErrors(final OneginiRegistrationError oneginiRegistrationError) {
@OneginiRegistrationError.RegistrationErrorType final int errorType = oneginiRegistrationError.getErrorType();
switch (errorType) {
case OneginiRegistrationError.DEVICE_DEREGISTERED:
showToast("The device was deregistered, please try registering again");
new DeregistrationUtil(this).onDeviceDeregistered();
break;
case OneginiRegistrationError.ACTION_CANCELED:
showToast("Registration was cancelled");
break;
case OneginiRegistrationError.NETWORK_CONNECTIVITY_PROBLEM:
case OneginiRegistrationError.SERVER_NOT_REACHABLE:
showToast("No internet connection.");
break;
case OneginiRegistrationError.OUTDATED_APP:
showToast("Please update this application in order to use it.");
break;
case OneginiRegistrationError.OUTDATED_OS:
showToast("Please update your Android version to use this application.");
break;
case OneginiRegistrationError.GENERAL_ERROR:
default:
// General error handling for other, less relevant errors
handleGeneralError(oneginiRegistrationError);
break;
}
}
private void handleGeneralError(final OneginiRegistrationError error) {
final StringBuilder stringBuilder = new StringBuilder("Error: ");
stringBuilder.append(error.getMessage());
stringBuilder.append(" Check logcat for more details.");
error.printStackTrace();
showToast(stringBuilder.toString());
}
Error code reference
In this reference you can find a description of all errors that can occur in the Android SDK.
Error | Code |
---|---|
NETWORK_CONNECTIVITY_PROBLEM | 9000 |
SERVER_NOT_REACHABLE | 9001 |
DEVICE_DEREGISTERED | 9002 |
USER_DEREGISTERED | 9003 |
OUTDATED_APP | 9004 |
OUTDATED_OS | 9005 |
ACTION_CANCELED | 9006 |
ACTION_ALREADY_IN_PROGRESS | 9007 |
DEVICE_REGISTRATION_ERROR | 9008 |
USER_NOT_AUTHENTICATED | 9010 |
PIN_BLACKLISTED | 9011 |
PIN_IS_A_SEQUENCE | 9012 |
PIN_USES_SIMILAR_DIGITS | 9013 |
WRONG_PIN_LENGTH | 9014 |
INVALID_AUTHENTICATOR | 9015 |
DEVICE_ALREADY_ENROLLED | 9016 |
ENROLLMENT_NOT_AVAILABLE | 9017 |
USER_ALREADY_ENROLLED | 9018 |
USER_DISENROLLED | 9020 |
MOBILE_AUTHENTICATION_NOT_ENROLLED | 9021 |
AUTHENTICATOR_DEREGISTERED | 9022 |
MOBILE_AUTHENTICATION_DISENROLLED | 9023 |
DATA_STORAGE_NOT_AVAILABLE | 9024 |
CUSTOM_AUTHENTICATOR_FAILURE | 9027 |
ALREADY_HANDLED | 9029 |
INVALID_DATETIME | 9031 |
GENERAL_ERROR | 10000 |
CONFIGURATION_ERROR | 10001 |
INVALID_STATE | 10002 |
LOCAL_DEREGISTRATION | 10003 |
AUTHENTICATOR_ALREADY_REGISTERED | 10004 |
FIDO_AUTHENTICATION_DISABLED (DEPRECATED) | 10005 |
AUTHENTICATOR_NOT_SUPPORTED | 10006 |
AUTHENTICATOR_NOT_REGISTERED | 10007 |
AUTHENTICATOR_PIN_DEREGISTRATION_NOT_POSSIBLE | 10008 |
LOCAL_LOGOUT | 10009 |
DEVICE_NOT_AUTHENTICATED | 10012 |
MOBILE_AUTHENTICATION_REQUEST_NOT_FOUND | 10013 |
INVALID_REQUEST | 10015 |
FIDO_SERVER_NOT_REACHABLE (DEPRECATED) | 10016 |
CUSTOM_AUTHENTICATION_DISABLED | 10017 |
NOT_HANDLEABLE | 10018 |
INVALID_IDENTITY_PROVIDER | 10020 |
CUSTOM_REGISTRATION_EXPIRED | 10021 |
CUSTOM_REGISTRATION_FAILURE | 10022 |
SINGLE_SIGN_ON_DISABLED | 10023 |
APP_INTEGRITY_FAILURE | 10024 |