Skip to content
Snippets Groups Projects
Commit 0baf48b4 authored by Demian Katz's avatar Demian Katz
Browse files

Set 404 status when users access missing records.

parent 84dbfee6
No related merge requests found
...@@ -309,6 +309,31 @@ class Bootstrap ...@@ -309,6 +309,31 @@ class Bootstrap
$this->events->attach('dispatch', $callback, 10000); $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. * Set up logging.
* *
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment