mirror of
https://code.castopod.org/adaures/castopod
synced 2025-04-19 13:01:19 +00:00
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.
This commit is contained in:
parent
0a66de3e6c
commit
9017e30bf4
@ -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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user