Skip to content

Commit

Permalink
fix(exception): use the code from the HTTP exception
Browse files Browse the repository at this point in the history
  • Loading branch information
KennethTrecy committed Sep 6, 2023
1 parent a16a43e commit e2ca752
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion app/Libraries/HTTPExceptionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use CodeIgniter\Debug\BaseExceptionHandler;
use CodeIgniter\Debug\ExceptionHandlerInterface;
use CodeIgniter\Exceptions\HTTPExceptionInterface;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use Fluent\Cors\Filters\CorsFilter;
Expand All @@ -24,7 +25,11 @@ public function handle(
$filter = new CorsFilter();
$response = $filter->after($request, $response);
$response
->setStatusCode($statusCode)
->setStatusCode(
$exception instanceof HTTPExceptionInterface
? $exception->getCode()
: $statusCode
)
->setJSON(
$exception instanceof APIException
? $exception->serialize()
Expand Down

0 comments on commit e2ca752

Please sign in to comment.