diff --git a/src/Controller/HealthController.php b/src/Controller/HealthController.php index 59f583a..7dfb78c 100644 --- a/src/Controller/HealthController.php +++ b/src/Controller/HealthController.php @@ -19,9 +19,11 @@ namespace OpenConext\MonitorBundle\Controller; use OpenConext\MonitorBundle\HealthCheck\HealthCheckChain; +use OpenConext\MonitorBundle\Value\HealthReport; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\Routing\Attribute\Route; +use Throwable; /** * Display the health state of the application. @@ -40,8 +42,11 @@ public function __construct( #[Route('/internal/health', name: 'monitor.internal_health', methods: ['GET'])] public function __invoke(): JsonResponse { - $statusResponse = $this->healthChecker->check(); - + try { + $statusResponse = $this->healthChecker->check(); + } catch (Throwable $exception) { + $statusResponse = HealthReport::buildStatusDown($exception->getMessage()); + } return $this->json($statusResponse, $statusResponse->getStatusCode()); } }