From fe51c01cf9555999327c6570690d7ae2192580fe Mon Sep 17 00:00:00 2001
From: Demian Katz <demian.katz@villanova.edu>
Date: Fri, 2 Dec 2016 08:42:54 -0500
Subject: [PATCH] Flag this error as a bad request.

---
 .../VuFind/Controller/CombinedController.php  |  4 +-
 .../src/VuFind/Exception/BadRequest.php       | 50 +++++++++++++++++++
 2 files changed, 53 insertions(+), 1 deletion(-)
 create mode 100644 module/VuFind/src/VuFind/Exception/BadRequest.php

diff --git a/module/VuFind/src/VuFind/Controller/CombinedController.php b/module/VuFind/src/VuFind/Controller/CombinedController.php
index 8f7bb0a43f5..6e6818d5561 100644
--- a/module/VuFind/src/VuFind/Controller/CombinedController.php
+++ b/module/VuFind/src/VuFind/Controller/CombinedController.php
@@ -251,7 +251,9 @@ class CombinedController extends AbstractSearch
                 return $this->redirect()->toRoute('home');
             }
             // If we have a weird value here, report it as an Exception:
-            throw new \Exception('Unexpected search type: "' . $type . '".');
+            throw new \VuFind\Exception\BadRequest(
+                'Unexpected search type: "' . $type . '".'
+            );
         }
     }
 
diff --git a/module/VuFind/src/VuFind/Exception/BadRequest.php b/module/VuFind/src/VuFind/Exception/BadRequest.php
new file mode 100644
index 00000000000..defff0e7c15
--- /dev/null
+++ b/module/VuFind/src/VuFind/Exception/BadRequest.php
@@ -0,0 +1,50 @@
+<?php
+/**
+ * "Bad Request" Exception
+ *
+ * PHP version 5
+ *
+ * Copyright (C) Villanova University 2016.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ * @category VuFind
+ * @package  Exceptions
+ * @author   Demian Katz <demian.katz@villanova.edu>
+ * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
+ * @link     https://vufind.org/wiki/development Wiki
+ */
+namespace VuFind\Exception;
+
+/**
+ * "Bad Request" Exception
+ *
+ * @category VuFind
+ * @package  Exceptions
+ * @author   Demian Katz <demian.katz@villanova.edu>
+ * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
+ * @link     https://vufind.org/wiki/development Wiki
+ */
+class BadRequest extends \Exception implements HttpStatusInterface
+{
+    /**
+     * Get HTTP status associated with this exception.
+     *
+     * @return int
+     */
+    public function getHttpStatus()
+    {
+        return 400;
+    }
+}
-- 
GitLab