| Code Coverage
| Lines | Functions and Methods | Classes and Traits
Total | 0.00% covered (danger) | 0.00% | 0 / 1 | 0.00% covered (danger) | 0.00% | 0 / 1 | CRAP | 0.00% covered (danger) | 0.00% | 0 / 1
Exceptions | 0.00% covered (danger) | 0.00% | 0 / 1 | 0.00% covered (danger) | 0.00% | 0 / 1 | 2 | 0.00% covered (danger) | 0.00% | 0 / 1
handler | 0.00% covered (danger) | 0.00% | 0 / 1 | 0.00% covered (danger) | 0.00% | 0 / 1 | 2 |

1 | <?php
2 |
3 | namespace Config;
4 |
5 | use CodeIgniter\Config\BaseConfig;
6 | use CodeIgniter\Debug\ExceptionHandler;
7 | use CodeIgniter\Debug\ExceptionHandlerInterface;
8 | use Psr\Log\LogLevel;
9 | use Throwable;
10 |
11 | /**
12 | * Setup how the exception handler works.
13 | */
14 | class Exceptions extends BaseConfig
15 | {
16 | /**
17 | * --------------------------------------------------------------------------
18 | * LOG EXCEPTIONS?
19 | * --------------------------------------------------------------------------
20 | * If true, then exceptions will be logged
21 | * through Services::Log.
22 | *
23 | * Default: true
24 | */
25 | public bool $log = true;
26 |
27 | /**
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.
33 | *
34 | * @var list<int>
35 | */
36 | public array $ignoreCodes = [404];
37 |
38 | /**
39 | * --------------------------------------------------------------------------
40 | * Error Views Path
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.
44 | *
45 | * Default: APPPATH.'Views/errors'
46 | */
47 | public string $errorViewPath = APPPATH . 'Views/errors';
48 |
49 | /**
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']
56 | *
57 | * @var list<string>
58 | */
59 | public array $sensitiveDataInTrace = [];
60 |
61 | /**
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.
67 | */
68 | public bool $logDeprecations = true;
69 |
70 | /**
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.
77 | *
78 | * The related `Config\Logger::$threshold` should be adjusted, if needed,
79 | * to capture logging the deprecations.
80 | */
81 | public string $deprecationLogLevel = LogLevel::WARNING;
82 |
83 | /*
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
90 | * response format.
91 | *
92 | * Custom handlers can be returned if you want to handle one or more specific
93 | * error codes yourself like:
94 | *
95 | * if (in_array($statusCode, [400, 404, 500])) {
96 | * return new \App\Libraries\MyExceptionHandler();
97 | * }
98 | * if ($exception instanceOf PageNotFoundException) {
99 | * return new \App\Libraries\MyExceptionHandler();
100 | * }
101 | */
102 | public function handler(int $statusCode, Throwable $exception): ExceptionHandlerInterface
103 | {
104 | return new ExceptionHandler($this);
105 | }
106 | }