Skip to content

Commit

Permalink
refactor: remove defaultExceptionHandler() and use ExceptionHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
kenjis committed Oct 27, 2022
1 parent 50b02c8 commit 9d5d44f
Showing 1 changed file with 4 additions and 37 deletions.
41 changes: 4 additions & 37 deletions system/Debug/Exceptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use CodeIgniter\Exceptions\HasExitCodeInterface;
use CodeIgniter\Exceptions\HTTPExceptionInterface;
use CodeIgniter\Exceptions\PageNotFoundException;
use CodeIgniter\HTTP\Exceptions\HTTPException;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use Config\Exceptions as ExceptionsConfig;
Expand Down Expand Up @@ -125,48 +124,16 @@ public function exceptionHandler(Throwable $exception)
]);
}

// For upgraded users.
// For upgraded users who did not update the config file.
if (! method_exists($this->config, 'handler')) {
$this->defaultExceptionHandler($exception, $statusCode, $exitCode);

return;
$handler = new ExceptionHandler($this->config);
} else {
$handler = $this->config->handler($statusCode, $exception);
}

$handler = $this->config->handler($statusCode, $exception);

$handler->handle($exception, $this->request, $this->response, $statusCode, $exitCode);
}

/**
* @deprecated This method is only for backward compatibility.
*/
private function defaultExceptionHandler(Throwable $exception, int $statusCode, int $exitCode)
{
if (! is_cli()) {
try {
$this->response->setStatusCode($statusCode);
} catch (HTTPException $e) {
// Workaround for invalid HTTP status code.
$statusCode = 500;
$this->response->setStatusCode($statusCode);
}

if (! headers_sent()) {
header(sprintf('HTTP/%s %s %s', $this->request->getProtocolVersion(), $this->response->getStatusCode(), $this->response->getReasonPhrase()), true, $statusCode);
}

if (strpos($this->request->getHeaderLine('accept'), 'text/html') === false) {
$this->respond(ENVIRONMENT === 'development' ? $this->collectVars($exception, $statusCode) : '', $statusCode)->send();

exit($exitCode);
}
}

$this->render($exception, $statusCode);

exit($exitCode);
}

/**
* The callback to be registered to `set_error_handler()`.
*
Expand Down

0 comments on commit 9d5d44f

Please sign in to comment.