1010use Symfony \Component \HttpFoundation \JsonResponse ;
1111use Symfony \Component \HttpFoundation \Response ;
1212use League \Flysystem \FilesystemOperator ;
13-
13+ use Psr \ Log \ LoggerInterface ;
1414
1515/**
1616 * @Route("/health")
1717 */
1818class HealthController extends AbstractController
1919{
20+ public function __construct (private LoggerInterface $ logger ){
21+
22+ }
23+
2024 /**
2125 * Checks for Database connection
2226 *
@@ -25,12 +29,16 @@ class HealthController extends AbstractController
2529 public function healthDB (EntityManagerInterface $ entityManager )
2630 {
2731 $ sql = "SELECT postgis_version() as postgis_version " ;
32+ $ this ->logger ->info ('get postgis version ' ,[
33+ 'sql ' => $ sql
34+ ]);
2835 try {
2936 $ stmt = $ entityManager ->getConnection ()->prepare ($ sql );
3037 $ result = $ stmt ->executeQuery ();
3138 return new JsonResponse ($ result ->fetchOne (), Response::HTTP_OK );
3239 } catch (Exception $ e ){
33- return new JsonResponse ($ e ->getMessage (), Response::HTTP_NOT_FOUND );
40+ $ this ->logger ->error ((string ) $ e );
41+ return new JsonResponse ($ e ->getMessage (), Response::HTTP_INTERNAL_SERVER_ERROR );
3442 }
3543 }
3644
@@ -41,12 +49,14 @@ public function healthDB(EntityManagerInterface $entityManager)
4149 */
4250 public function healthS3 (FilesystemOperator $ dataStorage )
4351 {
52+ $ this ->logger ->info ('list files from S3 bucket... ' );
4453 try {
4554 $ files = $ dataStorage ->listContents ('. ' , false );
4655 $ numFiles = count ($ files ->toArray ());
4756 return new JsonResponse ('found ' .$ numFiles .' files ' , Response::HTTP_OK );
4857 } catch (Exception $ e ) {
49- return new JsonResponse (False , Response::HTTP_NOT_FOUND );
58+ $ this ->logger ->error ((string ) $ e );
59+ return new JsonResponse ("fail to list files from S3 bucket " , Response::HTTP_INTERNAL_SERVER_ERROR );
5060 }
5161 }
5262
0 commit comments