1
0
mirror of https://github.com/wbbaddons/Tims-Chat.git synced 2024-12-22 21:40:08 +00:00

Throw InvalidArgumentException instead of NotFoundException

It provides better error messages for the user
This commit is contained in:
Tim Düsterhus 2013-06-18 00:28:56 +02:00
parent 38b29303d8
commit 8fe56d9e01
7 changed files with 28 additions and 6 deletions

View File

@ -125,6 +125,9 @@ public function validateSend() {
catch (\chat\system\command\UserNotFoundException $e) {
throw new UserInputException('text', WCF::getLanguage()->getDynamicVariable('chat.error.userNotFound', array('exception' => $e)));
}
catch (\InvalidArgumentException $e) {
throw new UserInputException('text', WCF::getLanguage()->getDynamicVariable('chat.error.invalidArgument', array('exception' => $e)));
}
}
else {
$this->parameters['type'] = Message::TYPE_NORMAL;

View File

@ -111,7 +111,7 @@ public function loadCommand() {
$class = '\chat\system\command\commands\\'.ucfirst(strtolower($parts[0])).'Command';
if (!class_exists($class)) {
throw new NotFoundException();
throw new NotFoundException($parts[0]);
}
return new $class($this);

View File

@ -10,4 +10,23 @@
* @package be.bastelstu.chat
* @subpackage system.chat.command
*/
class NotFoundException extends \Exception { }
class NotFoundException extends \Exception {
/**
* given command
* @var string
*/
private $command = '';
public function __construct($command) {
$this->command = $command;
}
/**
* Returns the given command
*
* @return string
*/
public function getCommand() {
return $this->command;
}
}

View File

@ -55,7 +55,7 @@ public function __construct(\chat\system\command\CommandHandler $commandHandler)
foreach ($color as $key => $val) {
if (isset(self::$colors[$val])) $color[$key] = self::$colors[$val];
else {
if (!$regex->match($val)) throw new \chat\system\command\NotFoundException();
if (!$regex->match($val)) throw new \InvalidArgumentException();
$matches = $regex->getMatches();
$val = $matches[1];

View File

@ -15,7 +15,7 @@ public function __construct(\chat\system\command\CommandHandler $commandHandler)
parent::__construct($commandHandler);
if (\wcf\util\StringUtil::toLowerCase($this->commandHandler->getParameters()) != 'the fish') {
throw new \chat\system\command\NotFoundException();
throw new \InvalidArgumentException();
}
$this->didInit();

View File

@ -31,7 +31,7 @@ public function __construct(\chat\system\command\CommandHandler $commandHandler)
$this->expires = min(max(-0x80000000, $expires), 0x7FFFFFFF);
}
catch (\wcf\system\exception\SystemException $e) {
throw new \chat\system\command\NotFoundException();
throw new \InvalidArgumentException();
}
$this->user = User::getUserByUsername($username);

View File

@ -26,7 +26,7 @@ public function __construct(\chat\system\command\CommandHandler $commandHandler)
$this->message = \wcf\util\StringUtil::trim($message);
}
catch (\wcf\system\exception\SystemException $e) {
throw new \chat\system\command\NotFoundException();
throw new \InvalidArgumentException();
}
$this->user = User::getUserByUsername($username);