Avoid logging SystemExceptions twice

SystemExceptions are already logged when the System ServiceProvider listens to the Message Logged event, this code used to be for ApplicationExceptions to bypass the fact that they were explicitly ignored by October's core exception handler.

ApplicationExceptions were added 27 Jan 2015 in 6a68036260
ApplicationExceptions were explicitly ignored in the core exception handler on 16 Feb 2015 in 237d97d87a (diff-b6bf0348130fdd1311473a97536310cdR20) and were explicitly logged in the System exception handler on the same day in 7b52e07b65 (diff-547f5794a63e9f138c33b20de8649b7eR20-R31)

Not sure why that was originally the case, but we've made the decision that ApplicationExceptions shouldn't be logged by default as they should occur semi-regularly in a healthy application (mostly as an expression of complex logical validation that triggers them based on bad user input): https://github.com/octobercms/october/pull/4569#issuecomment-550172508

Fixes octobercms/october#5253.
This commit is contained in:
Luke Towers 2020-08-28 13:57:12 -06:00
parent 6b214edf1f
commit 812c0552e8

View File

@ -1,6 +1,5 @@
<?php namespace System\Classes; <?php namespace System\Classes;
use Log;
use View; use View;
use Config; use Config;
use Cms\Classes\Theme; use Cms\Classes\Theme;
@ -8,6 +7,7 @@ use Cms\Classes\Router;
use Cms\Classes\Controller as CmsController; use Cms\Classes\Controller as CmsController;
use October\Rain\Exception\ErrorHandler as ErrorHandlerBase; use October\Rain\Exception\ErrorHandler as ErrorHandlerBase;
use October\Rain\Exception\SystemException; use October\Rain\Exception\SystemException;
use Symfony\Component\HttpFoundation\Response;
/** /**
* System Error Handler, this class handles application exception events. * System Error Handler, this class handles application exception events.
@ -34,18 +34,6 @@ class ErrorHandler extends ErrorHandlerBase
// return parent::handleException($proposedException); // return parent::handleException($proposedException);
// } // }
/**
* We are about to display an error page to the user,
* if it is an SystemException, this event should be logged.
* @return void
*/
public function beforeHandleError($exception)
{
if ($exception instanceof SystemException) {
Log::error($exception);
}
}
/** /**
* Looks up an error page using the CMS route "/error". If the route does not * Looks up an error page using the CMS route "/error". If the route does not
* exist, this function will use the error view found in the Cms module. * exist, this function will use the error view found in the Cms module.
@ -74,7 +62,7 @@ class ErrorHandler extends ErrorHandlerBase
} }
// Extract content from response object // Extract content from response object
if ($result instanceof \Symfony\Component\HttpFoundation\Response) { if ($result instanceof Response) {
$result = $result->getContent(); $result = $result->getContent();
} }