Skip to content

Commit

Permalink
chore(health): log exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
mborne committed Dec 3, 2024
1 parent 7780a8b commit 8c06e0d
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/Controller/Api/HealthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,17 @@
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use League\Flysystem\FilesystemOperator;

use Psr\Log\LoggerInterface;

/**
* @Route("/health")
*/
class HealthController extends AbstractController
{
public function __construct(private LoggerInterface $logger){

}

/**
* Checks for Database connection
*
Expand All @@ -25,12 +29,16 @@ class HealthController extends AbstractController
public function healthDB(EntityManagerInterface $entityManager)
{
$sql = "SELECT postgis_version() as postgis_version";
$this->logger->info('get postgis version',[
'sql' => $sql
]);
try{
$stmt = $entityManager->getConnection()->prepare($sql);
$result = $stmt->executeQuery();
return new JsonResponse($result->fetchOne(), Response::HTTP_OK);
} catch (Exception $e){
return new JsonResponse($e->getMessage(), Response::HTTP_NOT_FOUND);
$this->logger->error((string) $e);
return new JsonResponse($e->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR);
}
}

Expand All @@ -41,12 +49,14 @@ public function healthDB(EntityManagerInterface $entityManager)
*/
public function healthS3(FilesystemOperator $dataStorage)
{
$this->logger->info('list files from S3 bucket...');
try {
$files = $dataStorage->listContents('.', false);
$numFiles = count($files->toArray());
return new JsonResponse('found '.$numFiles.' files', Response::HTTP_OK);
} catch (Exception $e) {
return new JsonResponse(False, Response::HTTP_NOT_FOUND);
$this->logger->error((string) $e);
return new JsonResponse("fail to list files from S3 bucket", Response::HTTP_INTERNAL_SERVER_ERROR);
}
}

Expand Down

0 comments on commit 8c06e0d

Please sign in to comment.