diff --git a/module/VuFind/src/VuFind/Bootstrap.php b/module/VuFind/src/VuFind/Bootstrap.php index 447c2cd0fd4c392e73c01f6aac0e6cf9b07dfc4a..078c38f8a6e928f488abd3339c541efba00affcc 100644 --- a/module/VuFind/src/VuFind/Bootstrap.php +++ b/module/VuFind/src/VuFind/Bootstrap.php @@ -309,6 +309,31 @@ class Bootstrap $this->events->attach('dispatch', $callback, 10000); } + /** + * Set up custom 404 status based on exception type. + * + * @return void + */ + protected function initExceptionBased404s() + { + $callback = function($e) { + $exception = $e->getParam('exception'); + if (is_object($exception)) { + if ($exception instanceof \VuFind\Exception\RecordMissing) { + // TODO: it might be better to solve this problem by using a + // custom RouteNotFoundStrategy. + $response = $e->getResponse(); + if (!$response) { + $response = new HttpResponse(); + $e->setResponse($response); + } + $response->setStatusCode(404); + } + } + }; + $this->events->attach('dispatch.error', $callback); + } + /** * Set up logging. *