Skip to content

Commit 9d5d44f

Browse files
committed
refactor: remove defaultExceptionHandler() and use ExceptionHandler
1 parent 50b02c8 commit 9d5d44f

File tree

1 file changed

+4
-37
lines changed

1 file changed

+4
-37
lines changed

system/Debug/Exceptions.php

Lines changed: 4 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
use CodeIgniter\Exceptions\HasExitCodeInterface;
1616
use CodeIgniter\Exceptions\HTTPExceptionInterface;
1717
use CodeIgniter\Exceptions\PageNotFoundException;
18-
use CodeIgniter\HTTP\Exceptions\HTTPException;
1918
use CodeIgniter\HTTP\RequestInterface;
2019
use CodeIgniter\HTTP\ResponseInterface;
2120
use Config\Exceptions as ExceptionsConfig;
@@ -125,48 +124,16 @@ public function exceptionHandler(Throwable $exception)
125124
]);
126125
}
127126

128-
// For upgraded users.
127+
// For upgraded users who did not update the config file.
129128
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);
133132
}
134133

135-
$handler = $this->config->handler($statusCode, $exception);
136-
137134
$handler->handle($exception, $this->request, $this->response, $statusCode, $exitCode);
138135
}
139136

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-
170137
/**
171138
* The callback to be registered to `set_error_handler()`.
172139
*

0 commit comments

Comments
 (0)