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:
stevenh 2012-02-13 19:00:27 +00:00
parent 0c13716b84
commit 46f5f872ae

View file

@ -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>