Skip to content

Commit

Permalink
Merge pull request #137 from jdomingu98/126-nick-bug-colisin-en-el-nick
Browse files Browse the repository at this point in the history
feat: remove exception
  • Loading branch information
ruzafa8 authored Apr 27, 2024
2 parents 367f028 + 4a2c577 commit a224156
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 13 deletions.
9 changes: 0 additions & 9 deletions includes/exceptions/exceptions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
# define ERR_NO_NICKNAME_GIVEN ":No nickname given"
# define ERR_ERRONEUS_NICKNAME(nick) (nick) + " :Erroneus nickname"
# define ERR_NICKNAME_IN_USE(nick) (nick) + " :Nickname is already in use"
# define ERR_NICK_COLLISION(nick) (nick) + " :Nickname collision KILL"
# define ERR_PASSWD_MISMATCH ":Password incorrect"

# define ERR_INVITE_ONLY_CHAN(channel) (channel) + " :Cannot join channel (+i)"
Expand Down Expand Up @@ -72,14 +71,6 @@ class NeedMoreParamsException : public IRCException {
NeedMoreParamsException(const std::string &command) : IRCException("461", ERR_NEED_MORE_PARAMS(command)) {}
};

/**
* This exception is thrown when a nickname is already in use. (Nickname collision)
* It is thrown when a user tries to set a nickname the first time, and it is already in use.
*/
class NickCollisionException : public IRCException {
public:
NickCollisionException(const std::string &nickname) : IRCException("436", ERR_NICK_COLLISION(nickname)) {}
};

/**
* This exception is thrown when a nickname is already in use.
Expand Down
5 changes: 1 addition & 4 deletions src/commands/NickCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ NickCommand::~NickCommand() {}
*
* @throws `NoNicknameGivenException` If the nickname is empty
* @throws `ErroneousNicknameException` If the nickname is too long or invalid
* @throws `NickCollisionException` If the nickname is already in use and the user is not registered
* @throws `NicknameInUseException` If the nickname is already in use and the user is registered
*
*/
Expand All @@ -39,9 +38,7 @@ void NickCommand::execute(int clientFd) {
User &user = server.getUserByFd(clientFd);

if (server.isNicknameInUse(this->_nickname))
user.isRegistered()
? throw NicknameInUseException(this->_nickname)
: throw NickCollisionException(this->_nickname);
throw NicknameInUseException(this->_nickname);

if (!NickCommand::isValidNickname())
throw ErroneousNicknameException(this->_nickname);
Expand Down

0 comments on commit a224156

Please sign in to comment.