From 20ab93f1593996a51fdf0a95ab7fc10e5b1dc832 Mon Sep 17 00:00:00 2001 From: Florian Thoma Date: Tue, 28 May 2024 15:52:51 +1000 Subject: [PATCH] FIX return 404 instead of 500 for invalid model class, fixes #570 --- code/ModelAdmin.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/code/ModelAdmin.php b/code/ModelAdmin.php index 5af2b9c1c..1ef00def9 100644 --- a/code/ModelAdmin.php +++ b/code/ModelAdmin.php @@ -3,6 +3,7 @@ namespace SilverStripe\Admin; use InvalidArgumentException; +use Psr\Log\LoggerInterface; use SilverStripe\Control\Controller; use SilverStripe\Control\HTTPRequest; use SilverStripe\Control\HTTPResponse; @@ -162,7 +163,8 @@ protected function init() $this->modelTab = $this->unsanitiseClassName($this->modelTab); if (!$this->isManagedModel($this->modelTab)) { - throw new \RuntimeException(sprintf('ModelAdmin::init(): Invalid Model class %s', $this->modelTab)); + Injector::inst()->get(LoggerInterface::class)->error(sprintf('ModelAdmin::init(): Invalid Model class %s', $this->modelTab)); + return $this->httpError(404, 'Page not found'); } }