Sign Up Assistant | Error messages
The Sign Up Assistant provides customizable error messages for all phases of the process: registration, activation and password recovery. The following is a list of all error codes available and their relative default messages:
| SignUpErrorCodes enum | Default message |
|---|---|
| MISSING_USERNAME | User name is required |
| USERNAME_TOO_SHORT | User name is too short, min amount of characters is %s |
| USERNAME_TOO_LONG | User name is too long, max amount of characters is %s |
| USERNAME_ALREADY_IN_USE | Username: %s is already in use |
| MISSING_PASSWORD | Password is required |
| PASSWORD_TOO_SHORT | Password is too short, min. amount of characters is %s |
| PASSWORD_TOO_LONG | Password is too long, max. amount of characters is %s |
| MISSING_EMAIL | An email is required |
| INVALID_EMAIL | Email address: %s is invalid |
| EMAIL_ALREADY_IN_USE | Email address: %s is already in use |
| RECOVER_NO_USER | Password recovery error, username %s was not found |
| ACTIVATION_NO_ID | Invalid Activation. Session doesn't contain a database ID |
| ACTIVATION_INVALID_CODE | Invalid Activation Code received |
| GENERIC_DB_ERROR | Unexpected Database Error. Please contact our support |
| CUSTOM_ERROR | %s |
All these error messages can be customized provided that placeholders are maintained in the same number in which they appear in the default values.
For example let's say we want to customize the INVALID_EMAIL message:
The position doesn't matter in which the placeholder is moved, as long as they are preserved within the string.
Custom validation errors
The SignUpErrorCodes.CUSTOM_ERROR is a special code that can be used for custom validation purposes. We have seen in the first chapter that custom validation classes can be plugged into the Sign Up Assistant to check for extra fields. Let's go back to that example and review how a custom error can be thrown to interrupt the process and notify an error to the client:
@Override
public void init()
{
suac = new SignUpAssistantComponent();
suac.getConfig().extraFields = List.of("country", "age");
// Set limits for min/max name and password length
suac.getConfig().minUserNameLength = 4;
suac.getConfig().maxUserNameLength = 30;
suac.getConfig().minPasswordLength = 8;
suac.getConfig().maxPasswordLength = 30;
// Add a pre-process plugin for custom validation
suac.getConfig().preProcessPlugin = new ISignUpAssistantPlugin()
{
@Override
public void execute(User user, ISFSObject params, SignUpConfiguration config) throws SignUpValidationException
{
Integer age = params.getInt("age");
String country = params.getShortString("country");
if (age == null)
throw new SignUpValidationException(SignUpErrorCodes.CUSTOM_ERROR, "The age is missing");
if (age < 14)
throw new SignUpValidationException(SignUpErrorCodes.CUSTOM_ERROR, "You must be at least 14 years old to access this game");
if (country == null || country.length() < 2)
throw new SignUpValidationException(SignUpErrorCodes.CUSTOM_ERROR, "Please specify your country");
}
};
addRequestHandler(SignUpAssistantComponent.COMMAND_PREFIX, suac);
}
Wrapping up
This article completes the overview of the Sign Up Assistant. We recommend checking our complete Sign Up Example tutorial that puts together all you've learned here in this series.