You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@archiva.apache.org by ma...@apache.org on 2020/10/27 21:03:11 UTC
[archiva-redback-core] 01/04: Unified error messages
This is an automated email from the ASF dual-hosted git repository.
martin_s pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/archiva-redback-core.git
commit 2587c0a77e6d968aa6d0f5a1f4d03b3487c829a1
Author: Martin Stockhammer <ma...@apache.org>
AuthorDate: Sat Oct 24 15:50:50 2020 +0200
Unified error messages
---
.../org/apache/archiva/redback/rest/api/Constants.java | 1 +
.../redback/rest/services/v2/DefaultUserService.java | 18 +++++++++---------
2 files changed, 10 insertions(+), 9 deletions(-)
diff --git a/redback-integrations/redback-rest/redback-rest-api/src/main/java/org/apache/archiva/redback/rest/api/Constants.java b/redback-integrations/redback-rest/redback-rest-api/src/main/java/org/apache/archiva/redback/rest/api/Constants.java
index 54a03e8..0d0697e 100644
--- a/redback-integrations/redback-rest/redback-rest-api/src/main/java/org/apache/archiva/redback/rest/api/Constants.java
+++ b/redback-integrations/redback-rest/redback-rest-api/src/main/java/org/apache/archiva/redback/rest/api/Constants.java
@@ -37,6 +37,7 @@ public interface Constants
String ERR_USER_ID_INVALID = "redback:user.id.invalid";
String ERR_USER_FULL_NAME_EMPTY = "redback:user.fullname.empty";
String ERR_USER_EMAIL_EMPTY = "redback:user.email.empty";
+ String ERR_USER_EMAIL_INVALID = "redback:user.email.invalid";
String ERR_USER_ASSIGN_ROLE = "redback:user.role.assign.failure";
String ERR_USER_NOT_VALIDATED = "redback:user.not_validated";
String ERR_USER_ADMIN_EXISTS = "redback:user.admin.exists";
diff --git a/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/v2/DefaultUserService.java b/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/v2/DefaultUserService.java
index d7c64b3..53a4fb2 100644
--- a/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/v2/DefaultUserService.java
+++ b/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/v2/DefaultUserService.java
@@ -940,29 +940,29 @@ public class DefaultUserService
new RedbackServiceException( "issues during validating user", 422 );
if ( StringUtils.isEmpty( user.getUserId() ) )
{
- redbackServiceException.addErrorMessage( new ErrorMessage( "username.required", null ) );
+ redbackServiceException.addErrorMessage( ErrorMessage.of( ERR_USER_ID_EMPTY ) );
}
else
{
if ( !user.getUserId().matches( VALID_USERNAME_CHARS ) )
{
- redbackServiceException.addErrorMessage( new ErrorMessage( "username.invalid.characters", null ) );
+ redbackServiceException.addErrorMessage( ErrorMessage.of( ERR_USER_ID_INVALID ) );
}
}
if ( StringUtils.isEmpty( user.getFullName() ) )
{
- redbackServiceException.addErrorMessage( new ErrorMessage( "fullName.required", null ) );
+ redbackServiceException.addErrorMessage( ErrorMessage.of( ERR_USER_FULL_NAME_EMPTY ) );
}
if ( StringUtils.isEmpty( user.getEmail() ) )
{
- redbackServiceException.addErrorMessage( new ErrorMessage( "email.required", null ) );
+ redbackServiceException.addErrorMessage( ErrorMessage.of( ERR_USER_EMAIL_EMPTY ) );
}
if ( !StringUtils.equals( user.getPassword(), user.getConfirmPassword() ) )
{
- redbackServiceException.addErrorMessage( new ErrorMessage( "passwords.do.not.match", null ) );
+ redbackServiceException.addErrorMessage( ErrorMessage.of( ERR_AUTH_INVALID_CREDENTIALS, "nomatch" ) );
}
try
@@ -974,7 +974,7 @@ public class DefaultUserService
}
catch ( AddressException e )
{
- redbackServiceException.addErrorMessage( new ErrorMessage( "email.invalid", null ) );
+ redbackServiceException.addErrorMessage( ErrorMessage.of( ERR_USER_EMAIL_INVALID ) );
}
if ( !redbackServiceException.getErrorMessages().isEmpty() )
{
@@ -997,12 +997,12 @@ public class DefaultUserService
if ( ( StringUtils.isEmpty( user.getPassword() ) ) )
{
- throw new RedbackServiceException( new ErrorMessage( "password.required", null ) );
+ throw new RedbackServiceException( ErrorMessage.of( ERR_AUTH_INVALID_CREDENTIALS, "empty" ) );
}
}
catch ( UserManagerException e )
{
- throw new RedbackServiceException( new ErrorMessage( e.getMessage() ) );
+ throw new RedbackServiceException( ErrorMessage.of( ERR_AUTH_INVALID_CREDENTIALS, e.getMessage() ) );
}
}
@@ -1046,7 +1046,7 @@ public class DefaultUserService
}
catch ( UserManagerException e )
{
- throw new RedbackServiceException( new ErrorMessage( e.getMessage() ) );
+ throw new RedbackServiceException( ErrorMessage.of( ERR_USERMANAGER_FAIL, e.getMessage() ) );
}
}