Skip to content

Commit

Permalink
fix: incorrect HTTP status code may return
Browse files Browse the repository at this point in the history
  • Loading branch information
kenjis committed Jul 22, 2022
1 parent eda0ca8 commit e62b283
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
19 changes: 9 additions & 10 deletions system/Debug/Exceptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
namespace CodeIgniter\Debug;

use CodeIgniter\API\ResponseTrait;
use CodeIgniter\Exceptions\HasExitCodeException;
use CodeIgniter\Exceptions\HasHttpStatusCodeException;
use CodeIgniter\Exceptions\PageNotFoundException;
use CodeIgniter\HTTP\CLIRequest;
use CodeIgniter\HTTP\Exceptions\HTTPException;
Expand Down Expand Up @@ -312,18 +314,15 @@ protected function maskSensitiveData(&$trace, array $keysToMask, string $path =
*/
protected function determineCodes(Throwable $exception): array
{
$statusCode = abs($exception->getCode());
$statusCode = 500;
$exitStatus = EXIT_ERROR;

if ($statusCode < 100 || $statusCode > 599) {
$exitStatus = $statusCode + EXIT__AUTO_MIN;

if ($exitStatus > EXIT__AUTO_MAX) {
$exitStatus = EXIT_ERROR;
}
if ($exception instanceof HasHttpStatusCodeException) {
$statusCode = $exception->getCode();
}

$statusCode = 500;
} else {
$exitStatus = EXIT_ERROR;
if ($exception instanceof HasExitCodeException) {
$exitStatus = $exception->getCode();
}

return [$statusCode, $exitStatus];
Expand Down
3 changes: 2 additions & 1 deletion tests/system/Debug/ExceptionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@ public function testDetermineCodes(): void
$determineCodes = $this->getPrivateMethodInvoker($this->exception, 'determineCodes');

$this->assertSame([500, 9], $determineCodes(new RuntimeException('This.')));
$this->assertSame([500, 1], $determineCodes(new RuntimeException('This.', 167)));
$this->assertSame([500, 1], $determineCodes(new RuntimeException('That.', 600)));
$this->assertSame([404, 1], $determineCodes(new RuntimeException('There.', 404)));
$this->assertSame([500, 1], $determineCodes(new RuntimeException('There.', 404)));
}

public function testRenderBacktrace(): void
Expand Down

0 comments on commit e62b283

Please sign in to comment.