From 2a1024c19a4b495c64fb88d4260e8d7ebea1f9b5 Mon Sep 17 00:00:00 2001 From: Jared Whiklo Date: Mon, 2 Mar 2020 09:37:21 -0600 Subject: [PATCH] Catch Flysystem exceptions and report (#762) --- src/Flysystem/Fedora.php | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/src/Flysystem/Fedora.php b/src/Flysystem/Fedora.php index b90fc529..fe7af7ba 100644 --- a/src/Flysystem/Fedora.php +++ b/src/Flysystem/Fedora.php @@ -10,6 +10,7 @@ use Drupal\flysystem\Plugin\FlysystemPluginInterface; use Drupal\flysystem\Plugin\FlysystemUrlTrait; use Drupal\islandora\Flysystem\Adapter\FedoraAdapter; use Drupal\jwt\Authentication\Provider\JwtAuth; +use GuzzleHttp\Exception\ConnectException; use GuzzleHttp\HandlerStack; use GuzzleHttp\Client; use Islandora\Chullo\IFedoraApi; @@ -123,20 +124,28 @@ class Fedora implements FlysystemPluginInterface, ContainerFactoryPluginInterfac */ public function ensure($force = FALSE) { // Check fedora root for sanity. - $response = $this->fedora->getResourceHeaders(''); - - if ($response->getStatusCode() != 200) { - return [[ - 'severity' => RfcLogLevel::ERROR, - 'message' => '%url returned %status', - 'context' => [ - '%url' => $this->fedora->getBaseUri(), - '%status' => $response->getStatusCode(), + try { + $response = $this->fedora->getResourceHeaders(''); + $statusCode = $response->getStatusCode(); + $message = '%url returned %status'; + } + catch (ConnectException $e) { + // Fedora is unavailable. + $message = '%url is unavailable, cannot connect.'; + $statusCode = 500; + } + if ($statusCode != 200) { + return [ + [ + 'severity' => RfcLogLevel::ERROR, + 'message' => $message, + 'context' => [ + '%url' => $this->fedora->getBaseUri(), + '%status' => $statusCode, + ], ], - ], ]; } - return []; }