Add specific exception for invalid search type
Add specific exception for invalid search type

--- a/include/controller/Controller_Message.class.php
+++ b/include/controller/Controller_Message.class.php
@@ -166,6 +166,12 @@
 			}
 		}
 
+		if ($exception instanceof GitPHP_InvalidSearchTypeException) {
+			if ($this->resource)
+				return $this->resource->translate('Invalid search type');
+			return 'Invalid search type';
+		}
+
 		return $exception->getMessage();
 	}
 

--- a/include/controller/Controller_Search.class.php
+++ b/include/controller/Controller_Search.class.php
@@ -103,7 +103,7 @@
 		}
 
 		if (($this->params['searchtype'] !== GitPHP_Controller_Search::AuthorSearch) && ($this->params['searchtype'] !== GitPHP_Controller_Search::CommitterSearch) && ($this->params['searchtype'] !== GitPHP_Controller_Search::CommitSearch) && ($this->params['searchtype'] !== GitPHP_Controller_Search::FileSearch)) {
-			throw new GitPHP_MessageException(__('Invalid search type'), true);
+			throw new GitPHP_InvalidSearchTypeException();
 		}
 
 		if ((!isset($this->params['search'])) || (strlen($this->params['search']) < 2)) {

--- /dev/null
+++ b/include/exception/InvalidSearchTypeException.class.php
@@ -1,1 +1,25 @@
+<?php
+/**
+ * Custom exception when an invalid search type is given
+ *
+ * @author Christopher Han <xiphux@gmail.com>
+ * @copyright Copyright (c) 2012 Christopher Han
+ * @package GitPHP
+ * @subpackage Exception
+ */
+class GitPHP_InvalidSearchTypeException extends GitPHP_MessageException
+{
+	/**
+	 * Constructor
+	 *
+	 * @param string $message string
+	 * @param integer $code exception code
+	 */
+	public function __construct($message = '', $code = 0)
+	{
+		if (empty($message))
+			$message = 'Invalid search type';
+		parent::__construct($message, true, 200, $code);
+	}
+}
 

comments