Skip to content

Commit

Permalink
feat!: 404 override sets 404 status code by default
Browse files Browse the repository at this point in the history
  • Loading branch information
kenjis committed Feb 11, 2024
1 parent 75b5931 commit da455d4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 2 additions & 3 deletions system/CodeIgniter.php
Original file line number Diff line number Diff line change
Expand Up @@ -938,6 +938,8 @@ protected function runController($class)
*/
protected function display404errors(PageNotFoundException $e)
{
$this->response->setStatusCode($e->getCode());

// Is there a 404 Override available?
if ($override = $this->router->get404Override()) {
$returned = null;
Expand Down Expand Up @@ -966,9 +968,6 @@ protected function display404errors(PageNotFoundException $e)
return $this->response;
}

// Display 404 Errors
$this->response->setStatusCode($e->getCode());

$this->outputBufferingEnd();

// Throws new PageNotFoundException and remove exception message on production.
Expand Down
2 changes: 2 additions & 0 deletions tests/system/CodeIgniterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ public function testRun404Override(): void
$output = ob_get_clean();

$this->assertStringContainsString("Can't find a route for 'GET: pages/about'.", $output);
$this->assertSame(404, response()->getStatusCode());
}

public function testRun404OverrideControllerReturnsResponse(): void
Expand Down Expand Up @@ -194,6 +195,7 @@ public function testRun404OverrideByClosure(): void
$output = ob_get_clean();

$this->assertStringContainsString('404 Override by Closure.', $output);
$this->assertSame(404, response()->getStatusCode());
}

public function testControllersCanReturnString(): void
Expand Down

0 comments on commit da455d4

Please sign in to comment.