From 9017e30bf41bed8c2be65091bbc5fb1e63aef87a Mon Sep 17 00:00:00 2001 From: Yassine Doghri <yassine@doghri.fr> Date: Wed, 26 May 2021 11:37:41 +0000 Subject: [PATCH] fix(ux): redirect user to install page on database error in home page When first visiting the home page, users would see an error message that was normal because Castopod Host wasn't installed yet. From now on, the error is caught to redirect users directly to install page, preventing them seeing the error and thus, resulting in a better user experience. --- app/Controllers/HomeController.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/app/Controllers/HomeController.php b/app/Controllers/HomeController.php index 17ce49ff04..99e4d2bc9e 100644 --- a/app/Controllers/HomeController.php +++ b/app/Controllers/HomeController.php @@ -10,14 +10,19 @@ namespace App\Controllers; use App\Models\PodcastModel; use CodeIgniter\HTTP\RedirectResponse; +use mysqli_sql_exception; class HomeController extends BaseController { public function index(): RedirectResponse | string { - $model = new PodcastModel(); - - $allPodcasts = $model->findAll(); + try { + $allPodcasts = (new PodcastModel())->findAll(); + } catch (mysqli_sql_exception) { + // An error was caught when retrieving the podcasts from the database. + // Redirecting to install page because it is likely that Castopod Host has not been installed yet. + return redirect()->route('install'); + } // check if there's only one podcast to redirect user to it if (count($allPodcasts) === 1) { -- GitLab