|
15 | 15 | use CodeIgniter\Exceptions\HasExitCodeInterface; |
16 | 16 | use CodeIgniter\Exceptions\HTTPExceptionInterface; |
17 | 17 | use CodeIgniter\Exceptions\PageNotFoundException; |
18 | | -use CodeIgniter\HTTP\Exceptions\HTTPException; |
19 | 18 | use CodeIgniter\HTTP\RequestInterface; |
20 | 19 | use CodeIgniter\HTTP\ResponseInterface; |
21 | 20 | use Config\Exceptions as ExceptionsConfig; |
@@ -125,48 +124,16 @@ public function exceptionHandler(Throwable $exception) |
125 | 124 | ]); |
126 | 125 | } |
127 | 126 |
|
128 | | - // For upgraded users. |
| 127 | + // For upgraded users who did not update the config file. |
129 | 128 | if (! method_exists($this->config, 'handler')) { |
130 | | - $this->defaultExceptionHandler($exception, $statusCode, $exitCode); |
131 | | - |
132 | | - return; |
| 129 | + $handler = new ExceptionHandler($this->config); |
| 130 | + } else { |
| 131 | + $handler = $this->config->handler($statusCode, $exception); |
133 | 132 | } |
134 | 133 |
|
135 | | - $handler = $this->config->handler($statusCode, $exception); |
136 | | - |
137 | 134 | $handler->handle($exception, $this->request, $this->response, $statusCode, $exitCode); |
138 | 135 | } |
139 | 136 |
|
140 | | - /** |
141 | | - * @deprecated This method is only for backward compatibility. |
142 | | - */ |
143 | | - private function defaultExceptionHandler(Throwable $exception, int $statusCode, int $exitCode) |
144 | | - { |
145 | | - if (! is_cli()) { |
146 | | - try { |
147 | | - $this->response->setStatusCode($statusCode); |
148 | | - } catch (HTTPException $e) { |
149 | | - // Workaround for invalid HTTP status code. |
150 | | - $statusCode = 500; |
151 | | - $this->response->setStatusCode($statusCode); |
152 | | - } |
153 | | - |
154 | | - if (! headers_sent()) { |
155 | | - header(sprintf('HTTP/%s %s %s', $this->request->getProtocolVersion(), $this->response->getStatusCode(), $this->response->getReasonPhrase()), true, $statusCode); |
156 | | - } |
157 | | - |
158 | | - if (strpos($this->request->getHeaderLine('accept'), 'text/html') === false) { |
159 | | - $this->respond(ENVIRONMENT === 'development' ? $this->collectVars($exception, $statusCode) : '', $statusCode)->send(); |
160 | | - |
161 | | - exit($exitCode); |
162 | | - } |
163 | | - } |
164 | | - |
165 | | - $this->render($exception, $statusCode); |
166 | | - |
167 | | - exit($exitCode); |
168 | | - } |
169 | | - |
170 | 137 | /** |
171 | 138 | * The callback to be registered to `set_error_handler()`. |
172 | 139 | * |
|
0 commit comments