diff --git a/DNN Platform/Library/DotNetNuke.Library.csproj b/DNN Platform/Library/DotNetNuke.Library.csproj
index af36fccf982..3fd5675c886 100644
--- a/DNN Platform/Library/DotNetNuke.Library.csproj
+++ b/DNN Platform/Library/DotNetNuke.Library.csproj
@@ -230,6 +230,7 @@
+
diff --git a/DNN Platform/Library/Entities/Users/Exceptions/InvalidUserRegisterException.cs b/DNN Platform/Library/Entities/Users/Exceptions/InvalidUserRegisterException.cs
new file mode 100644
index 00000000000..963bde98f9a
--- /dev/null
+++ b/DNN Platform/Library/Entities/Users/Exceptions/InvalidUserRegisterException.cs
@@ -0,0 +1,28 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information
+
+namespace DotNetNuke.Entities.Users
+{
+ using System;
+
+ [Serializable]
+ public class InvalidUserRegisterException : Exception
+ {
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ public InvalidUserRegisterException()
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ ///
+ public InvalidUserRegisterException(string message)
+ : base(message)
+ {
+ }
+ }
+}
diff --git a/Dnn.AdminExperience/Dnn.PersonaBar.Extensions/Components/Users/RegisterController.cs b/Dnn.AdminExperience/Dnn.PersonaBar.Extensions/Components/Users/RegisterController.cs
index 3ad31fa538f..505aa4d08da 100644
--- a/Dnn.AdminExperience/Dnn.PersonaBar.Extensions/Components/Users/RegisterController.cs
+++ b/Dnn.AdminExperience/Dnn.PersonaBar.Extensions/Components/Users/RegisterController.cs
@@ -243,7 +243,7 @@ public UserBasicDto Register(RegisterationDetails registerationDetails)
if (createStatus != UserCreateStatus.Success)
{
- throw new Exception(UserController.GetUserCreateStatus(createStatus));
+ throw new InvalidUserRegisterException(UserController.GetUserCreateStatus(createStatus));
}
// if (registerationDetails.IgnoreRegistrationMode)
diff --git a/Dnn.AdminExperience/Dnn.PersonaBar.Extensions/Services/UsersController.cs b/Dnn.AdminExperience/Dnn.PersonaBar.Extensions/Services/UsersController.cs
index f85f7fcd90f..ef7e880f9eb 100644
--- a/Dnn.AdminExperience/Dnn.PersonaBar.Extensions/Services/UsersController.cs
+++ b/Dnn.AdminExperience/Dnn.PersonaBar.Extensions/Services/UsersController.cs
@@ -69,9 +69,16 @@ public HttpResponseMessage CreateUser(CreateUserContract contract)
: null);
}
catch (Exception ex)
- {
- Logger.Error(ex);
- return this.Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message);
+ {
+ Logger.Error(ex);
+ if (ex.GetType() == typeof(InvalidUserRegisterException))
+ {
+ return this.Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.Message);
+ }
+ else
+ {
+ return this.Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message);
+ }
}
}