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>
|
||||
public void AddUser(User user)
|
||||
{
|
||||
if (!TShock.Groups.GroupExists(user.Group))
|
||||
throw new GroupNotExistsException(user.Group);
|
||||
|
||||
int ret;
|
||||
try
|
||||
{
|
||||
if (!TShock.Groups.GroupExists(user.Group))
|
||||
throw new GroupNotExistsException(user.Group);
|
||||
|
||||
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);
|
||||
ret = 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);
|
||||
}
|
||||
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>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue