5
use CodeIgniter\Config\BaseConfig;
6
use CodeIgniter\Debug\ExceptionHandler;
7
use CodeIgniter\Debug\ExceptionHandlerInterface;
12
* Setup how the exception handler works.
14
class Exceptions extends BaseConfig
17
* --------------------------------------------------------------------------
19
* --------------------------------------------------------------------------
20
* If true, then exceptions will be logged
21
* through Services::Log.
25
public bool $log = true;
28
* --------------------------------------------------------------------------
29
* DO NOT LOG STATUS CODES
30
* --------------------------------------------------------------------------
31
* Any status codes here will NOT be logged if logging is turned on.
32
* By default, only 404 (Page Not Found) exceptions are ignored.
36
public array $ignoreCodes = [404];
39
* --------------------------------------------------------------------------
41
* --------------------------------------------------------------------------
42
* This is the path to the directory that contains the 'cli' and 'html'
43
* directories that hold the views used to generate errors.
45
* Default: APPPATH.'Views/errors'
47
public string $errorViewPath = APPPATH . 'Views/errors';
50
* --------------------------------------------------------------------------
51
* HIDE FROM DEBUG TRACE
52
* --------------------------------------------------------------------------
53
* Any data that you would like to hide from the debug trace.
54
* In order to specify 2 levels, use "/" to separate.
55
* ex. ['server', 'setup/password', 'secret_token']
59
public array $sensitiveDataInTrace = [];
62
* --------------------------------------------------------------------------
63
* WHETHER TO THROW AN EXCEPTION ON DEPRECATED ERRORS
64
* --------------------------------------------------------------------------
65
* If set to `true`, DEPRECATED errors are only logged and no exceptions are
66
* thrown. This option also works for user deprecations.
68
public bool $logDeprecations = true;
71
* --------------------------------------------------------------------------
72
* LOG LEVEL THRESHOLD FOR DEPRECATIONS
73
* --------------------------------------------------------------------------
74
* If `$logDeprecations` is set to `true`, this sets the log level
75
* to which the deprecation will be logged. This should be one of the log
76
* levels recognized by PSR-3.
78
* The related `Config\Logger::$threshold` should be adjusted, if needed,
79
* to capture logging the deprecations.
81
public string $deprecationLogLevel = LogLevel::WARNING;
84
* DEFINE THE HANDLERS USED
85
* --------------------------------------------------------------------------
86
* Given the HTTP status code, returns exception handler that
87
* should be used to deal with this error. By default, it will run CodeIgniter's
88
* default handler and display the error information in the expected format
89
* for CLI, HTTP, or AJAX requests, as determined by is_cli() and the expected
92
* Custom handlers can be returned if you want to handle one or more specific
93
* error codes yourself like:
95
* if (in_array($statusCode, [400, 404, 500])) {
96
* return new \App\Libraries\MyExceptionHandler();
98
* if ($exception instanceOf PageNotFoundException) {
99
* return new \App\Libraries\MyExceptionHandler();
102
public function handler(int $statusCode, Throwable $exception): ExceptionHandlerInterface
104
return new ExceptionHandler($this);