Skip to content

Commit e433ecd

Browse files
author
dereuromark
committed
Add missing 404 whitelist.
1 parent 13b8ad0 commit e433ecd

File tree

2 files changed

+27
-30
lines changed

2 files changed

+27
-30
lines changed

src/Error/ErrorHandler.php

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Cake\Error\ErrorHandler as CoreErrorHandler;
66
use Cake\Log\Log;
77
use Exception;
8+
use Tools\Error\Middleware\ErrorHandlerMiddleware;
89

910
/**
1011
* Custom ErrorHandler to not mix the 404 exceptions with the rest of "real" errors in the error.log file.
@@ -37,21 +38,7 @@ class ErrorHandler extends CoreErrorHandler {
3738
* @return bool
3839
*/
3940
protected function _logException(Exception $exception) {
40-
$blacklist = [
41-
'Cake\Routing\Exception\MissingControllerException',
42-
'Cake\Routing\Exception\MissingActionException',
43-
'Cake\Routing\Exception\PrivateActionException',
44-
'Cake\Routing\Exception\NotFoundException',
45-
'Cake\Datasource\Exception\RecordNotFoundException',
46-
'Cake\Network\Exception\MethodNotAllowedException',
47-
'Cake\Network\Exception\BadRequestException',
48-
'Cake\Network\Exception\ForbiddenException',
49-
'Cake\Network\Exception\GoneException',
50-
'Cake\Network\Exception\ConflictException',
51-
'Cake\Network\Exception\InvalidCsrfToken',
52-
'Cake\Network\Exception\UnauthorizedException',
53-
'Cake\Network\Exception\NotAcceptableException',
54-
];
41+
$blacklist = ErrorHandlerMiddleware::$blacklist;
5542
if (isset($this->_options['log404'])) {
5643
$blacklist = $this->_options['log404'];
5744
}

src/Error/Middleware/ErrorHandlerMiddleware.php

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,13 @@
33
namespace Tools\Error\Middleware;
44

55
use Cake\Core\Configure;
6+
use Cake\Datasource\Exception\RecordNotFoundException;
67
use Cake\Error\Middleware\ErrorHandlerMiddleware as CoreErrorHandlerMiddleware;
78
use Cake\Log\Log;
9+
use Cake\Network\Exception\BadRequestException;
10+
use Cake\Network\Exception\MethodNotAllowedException;
11+
use Cake\Network\Exception\NotAcceptableException;
12+
use Cake\Network\Exception\NotFoundException;
813

914
/**
1015
* Error handling middleware.
@@ -30,6 +35,25 @@
3035
*/
3136
class ErrorHandlerMiddleware extends CoreErrorHandlerMiddleware {
3237

38+
/**
39+
* @var array
40+
*/
41+
public static $blacklist = [
42+
NotFoundException::class,
43+
MethodNotAllowedException::class,
44+
NotAcceptableException::class,
45+
RecordNotFoundException::class,
46+
BadRequestException::class,
47+
'Cake\Network\Exception\GoneException',
48+
'Cake\Network\Exception\ConflictException',
49+
'Cake\Network\Exception\InvalidCsrfToken',
50+
'Cake\Network\Exception\UnauthorizedException',
51+
'Cake\Routing\Exception\MissingControllerException',
52+
'Cake\Routing\Exception\MissingActionException',
53+
'Cake\Routing\Exception\PrivateActionException',
54+
'Cake\Routing\Exception\NotFoundException',
55+
];
56+
3357
/**
3458
* @param string|callable|null $renderer The renderer or class name
3559
* to use or a callable factory.
@@ -53,21 +77,7 @@ public function __construct($renderer = null, array $config = []) {
5377
* @return void
5478
*/
5579
protected function logException($request, $exception) {
56-
$blacklist = [
57-
'Cake\Routing\Exception\MissingControllerException',
58-
'Cake\Routing\Exception\MissingActionException',
59-
'Cake\Routing\Exception\PrivateActionException',
60-
'Cake\Routing\Exception\NotFoundException',
61-
'Cake\Datasource\Exception\RecordNotFoundException',
62-
'Cake\Network\Exception\MethodNotAllowedException',
63-
'Cake\Network\Exception\BadRequestException',
64-
'Cake\Network\Exception\ForbiddenException',
65-
'Cake\Network\Exception\GoneException',
66-
'Cake\Network\Exception\ConflictException',
67-
'Cake\Network\Exception\InvalidCsrfToken',
68-
'Cake\Network\Exception\UnauthorizedException',
69-
'Cake\Network\Exception\NotAcceptableException',
70-
];
80+
$blacklist = static::$blacklist;
7181
if (isset($this->_config['log404'])) {
7282
$blacklist = $this->_config['log404'];
7383
}

0 commit comments

Comments
 (0)