From 46f5f872ae02ed3ddf6aeea58ccefe4368b3822a Mon Sep 17 00:00:00 2001 From: stevenh Date: Mon, 13 Feb 2012 19:00:27 +0000 Subject: [PATCH] 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 --- TShockAPI/DB/UserManager.cs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/TShockAPI/DB/UserManager.cs b/TShockAPI/DB/UserManager.cs index 70423dfb..29944e18 100644 --- a/TShockAPI/DB/UserManager.cs +++ b/TShockAPI/DB/UserManager.cs @@ -50,20 +50,22 @@ namespace TShockAPI.DB /// User user 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); } ///