From 91827930c004bd47bbdbe960e487115396605fa9 Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Wed, 27 Oct 2021 10:21:16 +0100 Subject: [PATCH] Improve exception --- app/controllers/api/health.php | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/app/controllers/api/health.php b/app/controllers/api/health.php index 96b5f82b65..7b215f74e9 100644 --- a/app/controllers/api/health.php +++ b/app/controllers/api/health.php @@ -46,14 +46,18 @@ App::get('/v1/health/db') ->action(function ($response, $utopia) { /** @var Appwrite\Utopia\Response $response */ /** @var Utopia\App $utopia */ - $db = $utopia->getResource('db'); /* @var $db PDO */ + try { + $db = $utopia->getResource('db'); /* @var $db PDO */ - // Run a small test to check the connection - $statement = $db->prepare("SELECT 1;"); - - $statement->closeCursor(); - - $statement->execute(); + // Run a small test to check the connection + $statement = $db->prepare("SELECT 1;"); + + $statement->closeCursor(); + + $statement->execute(); + } catch (Exception $_e) { + throw new Exception('Database is not available', 500); + } return $response->json(['status' => 'OK']); });