nhance/app/Debug/CorsExceptionHandler.php
2026-06-15 16:32:42 +05:30

40 lines
1022 B
PHP

<?php
namespace App\Debug;
use App\Filters\Cors;
use CodeIgniter\Debug\ExceptionHandler;
use CodeIgniter\Debug\ExceptionHandlerInterface;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use Config\Exceptions;
use Throwable;
/**
* Ensures CORS headers are present on uncaught exception responses.
*
* The global Cors filter's after() method is not invoked when an exception
* bypasses the normal filter pipeline.
*/
class CorsExceptionHandler implements ExceptionHandlerInterface
{
protected ExceptionHandler $handler;
public function __construct(Exceptions $config)
{
$this->handler = new ExceptionHandler($config);
}
public function handle(
Throwable $exception,
RequestInterface $request,
ResponseInterface $response,
int $statusCode,
int $exitCode
): void {
(new Cors())->after($request, $response);
$this->handler->handle($exception, $request, $response, $statusCode, $exitCode);
}
}