This repository was archived by the owner on Aug 2, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +11
-2
lines changed Expand file tree Collapse file tree 2 files changed +11
-2
lines changed Original file line number Diff line number Diff line change 55namespace App \Controller ;
66
77use App \Repository \LastUpdateRepository ;
8+ use RuntimeException ;
89use Symfony \Component \HttpFoundation \Response ;
910
1011final class DefaultController
@@ -16,7 +17,11 @@ public function __construct(
1617
1718 public function index (): Response
1819 {
19- $ lastUpdate = $ this ->repository ->get ()->format ('Y-m-d H:i:s ' );
20+ try {
21+ $ lastUpdate = $ this ->repository ->get ()->format ('Y-m-d H:i:s ' );
22+ } catch (RuntimeException $ e ) {
23+ $ lastUpdate = $ e ->getMessage ();
24+ }
2025
2126 return new Response (<<<HTML
2227<html>
Original file line number Diff line number Diff line change 88use DateTimeImmutable ;
99use PDO ;
1010use PDOException ;
11+ use RuntimeException ;
1112
1213final class LastUpdateRepository
1314{
@@ -20,8 +21,11 @@ public function __construct(
2021 public function get (): DateTimeImmutable
2122 {
2223 $ stmt = $ this ->db ->query ('SELECT * FROM last_update; ' );
24+ if (false === ($ date = $ stmt ->fetchColumn ())) {
25+ throw new RuntimeException ('Data has never been updated. ' );
26+ }
2327
24- return new DateTimeImmutable ($ stmt -> fetchColumn () );
28+ return new DateTimeImmutable ($ date );
2529 }
2630
2731 public function save (): void
You can’t perform that action at this time.
0 commit comments