Moved local exceptions outside of try block in AddUser so the calling code gets the original exception and not a generic one
Also added details of the SQL exception message into the message of the UserManagerException so its easier to determine the actual error when the exception message is returned / printed out
This commit is contained in:
parent
0c13716b84
commit
46f5f872ae
1 changed files with 10 additions and 8 deletions
|
|
@ -50,20 +50,22 @@ namespace TShockAPI.DB
|
||||||
/// <param name="user">User user</param>
|
/// <param name="user">User user</param>
|
||||||
public void AddUser(User user)
|
public void AddUser(User user)
|
||||||
{
|
{
|
||||||
|
if (!TShock.Groups.GroupExists(user.Group))
|
||||||
|
throw new GroupNotExistsException(user.Group);
|
||||||
|
|
||||||
|
int ret;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (!TShock.Groups.GroupExists(user.Group))
|
ret = database.Query("INSERT INTO Users (Username, Password, UserGroup, IP) VALUES (@0, @1, @2, @3);", user.Name,
|
||||||
throw new GroupNotExistsException(user.Group);
|
TShock.Utils.HashPassword(user.Password), user.Group, user.Address);
|
||||||
|
|
||||||
if (
|
|
||||||
database.Query("INSERT INTO Users (Username, Password, UserGroup, IP) VALUES (@0, @1, @2, @3);", user.Name,
|
|
||||||
TShock.Utils.HashPassword(user.Password), user.Group, user.Address) < 1)
|
|
||||||
throw new UserExistsException(user.Name);
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
throw new UserManagerException("AddUser SQL returned an error", ex);
|
throw new UserManagerException("AddUser SQL returned an error (" + ex.Message + ")", ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (1 > ret)
|
||||||
|
throw new UserExistsException(user.Name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue