Skip to content

Commit 8c06e0d

Browse files
committed
chore(health): log exceptions
1 parent 7780a8b commit 8c06e0d

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/Controller/Api/HealthController.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,17 @@
1010
use Symfony\Component\HttpFoundation\JsonResponse;
1111
use Symfony\Component\HttpFoundation\Response;
1212
use League\Flysystem\FilesystemOperator;
13-
13+
use Psr\Log\LoggerInterface;
1414

1515
/**
1616
* @Route("/health")
1717
*/
1818
class 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

Comments
 (0)