Skip to content
Snippets Groups Projects
Unverified Commit 9017e30b authored by Yassine Doghri's avatar Yassine Doghri
Browse files

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.
parent 0a66de3e
No related branches found
No related tags found
No related merge requests found
...@@ -10,14 +10,19 @@ namespace App\Controllers; ...@@ -10,14 +10,19 @@ namespace App\Controllers;
use App\Models\PodcastModel; use App\Models\PodcastModel;
use CodeIgniter\HTTP\RedirectResponse; use CodeIgniter\HTTP\RedirectResponse;
use mysqli_sql_exception;
class HomeController extends BaseController class HomeController extends BaseController
{ {
public function index(): RedirectResponse | string public function index(): RedirectResponse | string
{ {
$model = new PodcastModel(); try {
$allPodcasts = (new PodcastModel())->findAll();
$allPodcasts = $model->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 // check if there's only one podcast to redirect user to it
if (count($allPodcasts) === 1) { if (count($allPodcasts) === 1) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment