Skip to content

Commit

Permalink
Create User invalid request has a response which returns 500 #5228 (#…
Browse files Browse the repository at this point in the history
…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 <armagan.pekatik@trilogy.com>
  • Loading branch information
armaganpekatik and armaganpekatik authored Aug 7, 2022
1 parent ff59c18 commit c0219b1
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 4 deletions.
1 change: 1 addition & 0 deletions DNN Platform/Library/DotNetNuke.Library.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@
<Compile Include="Entities\Portals\PortalAliasExtensions.cs" />
<Compile Include="Entities\Portals\PortalSettingUpdatedEventArgs.cs" />
<Compile Include="Entities\Portals\PortalTemplateEventArgs.cs" />
<Compile Include="Entities\Users\Exceptions\InvalidUserRegisterException.cs" />
<Compile Include="Entities\Users\UpdateUserEventArgs.cs" />
<Compile Include="Entities\Content\ContentTypeMemberNameFixer.cs" />
<Compile Include="Collections\EnumerableExtensions.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -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
{
/// <summary>
/// Initializes a new instance of the <see cref="InvalidUserRegisterException"/> class.
/// </summary>
public InvalidUserRegisterException()
{
}

/// <summary>
/// Initializes a new instance of the <see cref="InvalidUserRegisterException"/> class.
/// </summary>
/// <param name="message"></param>
public InvalidUserRegisterException(string message)
: base(message)
{
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

Expand Down

0 comments on commit c0219b1

Please sign in to comment.