From c0219b1a1d957546bd25b0e2f87def760ab93409 Mon Sep 17 00:00:00 2001 From: Armagan Pekatik <42939859+armaganpekatik@users.noreply.github.com> Date: Sun, 7 Aug 2022 15:22:23 +0300 Subject: [PATCH] Create User invalid request has a response which returns 500 #5228 (#5229) * encoding url adding to temp * Password error code change * url fix * rename exception type * all register errors should be logged Co-authored-by: armaganpekatik --- .../Library/DotNetNuke.Library.csproj | 1 + .../InvalidUserRegisterException.cs | 28 +++++++++++++++++++ .../Components/Users/RegisterController.cs | 2 +- .../Services/UsersController.cs | 13 +++++++-- 4 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 DNN Platform/Library/Entities/Users/Exceptions/InvalidUserRegisterException.cs diff --git a/DNN Platform/Library/DotNetNuke.Library.csproj b/DNN Platform/Library/DotNetNuke.Library.csproj index 81475dc4750..73877881cb1 100644 --- a/DNN Platform/Library/DotNetNuke.Library.csproj +++ b/DNN Platform/Library/DotNetNuke.Library.csproj @@ -225,6 +225,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); + } } }