diff --git a/app/Controllers/HomeController.php b/app/Controllers/HomeController.php index 17ce49ff04dcde8e5cb144ab132dadc0ea463300..99e4d2bc9e6bbfc46cfd30d3fae46f734fdf2805 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) {