From 5e0818e9c532e9c7f54f5ccd4c184dc8643e84df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20Sch=C3=BCrmann?= Date: Wed, 15 Oct 2025 23:36:09 +0200 Subject: [PATCH 1/2] replace 404 and 406 CRITICAL errors with NOTICE and useful information --- libraries/src/Exception/ExceptionHandler.php | 43 +++++++++++++++----- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/libraries/src/Exception/ExceptionHandler.php b/libraries/src/Exception/ExceptionHandler.php index 7fbe87fd4440c..a40bb56560f73 100644 --- a/libraries/src/Exception/ExceptionHandler.php +++ b/libraries/src/Exception/ExceptionHandler.php @@ -14,6 +14,9 @@ use Joomla\CMS\Event\Application\AfterInitialiseDocumentEvent; use Joomla\CMS\Factory; use Joomla\CMS\Log\Log; +use Joomla\CMS\Router\Exception\RouteNotFoundException; +use Joomla\CMS\Application\Exception\NotAcceptable; +use Joomla\CMS\Uri\Uri; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; @@ -221,18 +224,38 @@ protected static function isException($error) */ protected static function logException(\Throwable $error) { + // Handle common client errors as notices instead of critical errors + if ($error instanceof RouteNotFoundException) { + $level = Log::NOTICE; + $message = \sprintf( + 'Page not found (404): %s. Message: "%s"', + Uri::getInstance()->toString(), + $error->getMessage() + ); + $category = 'client-error'; + } elseif ($error instanceof NotAcceptable) { + $level = Log::NOTICE; + $message = \sprintf( + 'Not acceptable (406): %s. Message: "%s"', + Uri::getInstance()->toString(), + $error->getMessage() + ); + $category = 'client-error'; + } else { + // For all other errors, log a critical error with the full stack trace. + $level = Log::CRITICAL; + $message = \sprintf( + 'Uncaught Throwable of type %1$s thrown with message "%2$s". Stack trace: %3$s', + \get_class($error), + $error->getMessage(), + $error->getTraceAsString() + ); + $category = 'error'; + } + // Try to log the error, but don't let the logging cause a fatal error try { - Log::add( - \sprintf( - 'Uncaught Throwable of type %1$s thrown with message "%2$s". Stack trace: %3$s', - \get_class($error), - $error->getMessage(), - $error->getTraceAsString() - ), - Log::CRITICAL, - 'error' - ); + Log::add($message, $level, $category); } catch (\Throwable) { // Logging failed, don't make a stink about it though } From 0d09aa19575b01b5ec5eb56cc8512c9dc7c621a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20Sch=C3=BCrmann?= Date: Thu, 16 Oct 2025 18:13:01 +0200 Subject: [PATCH 2/2] alpha sort use statements --- libraries/src/Exception/ExceptionHandler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/src/Exception/ExceptionHandler.php b/libraries/src/Exception/ExceptionHandler.php index a40bb56560f73..9d29c8a5996eb 100644 --- a/libraries/src/Exception/ExceptionHandler.php +++ b/libraries/src/Exception/ExceptionHandler.php @@ -10,12 +10,12 @@ namespace Joomla\CMS\Exception; use Joomla\CMS\Application\CMSApplication; +use Joomla\CMS\Application\Exception\NotAcceptable; use Joomla\CMS\Error\AbstractRenderer; use Joomla\CMS\Event\Application\AfterInitialiseDocumentEvent; use Joomla\CMS\Factory; use Joomla\CMS\Log\Log; use Joomla\CMS\Router\Exception\RouteNotFoundException; -use Joomla\CMS\Application\Exception\NotAcceptable; use Joomla\CMS\Uri\Uri; // phpcs:disable PSR1.Files.SideEffects