Skip to content

Commit 0a5824d

Browse files
frostbittenNetrilix
authored andcommitted
update page404() to respond with 404 code and other (#567)
Update page404() and pageDatabaseError() to use proper HTTP status codes Use pageDatabaseError() if UserSession hits a PDOException Use BaseController instead of AccountController for database errors
1 parent 17ab194 commit 0a5824d

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

userfrosting/controllers/BaseController.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ public function __construct($app){
3535
* Request type: GET
3636
*/
3737
public function page404(){
38-
$this->_app->render('errors/404.twig');
38+
$twig = $this->_app->view()->getEnvironment();
39+
$this->_app->halt(404,$twig->render('errors/404.twig', $twig->getGlobals()));
3940
}
4041

4142
/**
@@ -46,7 +47,8 @@ public function page404(){
4647
* Request type: GET
4748
*/
4849
public function pageDatabaseError(){
49-
$this->_app->render('errors/database.twig');
50+
$twig = $this->_app->view()->getEnvironment();
51+
$this->_app->halt(503,$twig->render('errors/database.twig', $twig->getGlobals()));
5052
}
5153

5254
/**

userfrosting/middleware/usersession/UserSession.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ public function setup(){
9191
// If we can't connect to the DB, then we can't create an authenticated user. That's ok if we're in installation mode.
9292
error_log("Unable to authenticate user because the database is not yet initialized, invalid, or inaccessible. Falling back to guest user.");
9393
error_log($e->getTraceAsString());
94+
$controller = new BaseController($this->app);
95+
return $controller->pageDatabaseError();
9496
}
9597
}
9698
}

0 commit comments

Comments
 (0)