Skip to content

Commit 5383d46

Browse files
committed
fix: incorrect HTTP status code may return
1 parent 40ee9c8 commit 5383d46

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

system/Debug/Exceptions.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use CodeIgniter\API\ResponseTrait;
1515
use CodeIgniter\Exceptions\PageNotFoundException;
1616
use CodeIgniter\HTTP\CLIRequest;
17+
use CodeIgniter\HTTP\Exceptions\HTTPException;
1718
use CodeIgniter\HTTP\IncomingRequest;
1819
use CodeIgniter\HTTP\Response;
1920
use Config\Exceptions as ExceptionsConfig;
@@ -115,7 +116,14 @@ public function exceptionHandler(Throwable $exception)
115116
}
116117

117118
if (! is_cli()) {
118-
$this->response->setStatusCode($statusCode);
119+
try {
120+
$this->response->setStatusCode($statusCode);
121+
} catch (HTTPException $e) {
122+
// Workaround for invalid HTTP status code.
123+
$statusCoden = 500;
124+
$this->response->setStatusCode($statusCoden);
125+
}
126+
119127
if (! headers_sent()) {
120128
header(sprintf('HTTP/%s %s %s', $this->request->getProtocolVersion(), $this->response->getStatusCode(), $this->response->getReasonPhrase()), true, $statusCode);
121129
}

0 commit comments

Comments
 (0)