Browse Source

Catch Flysystem exceptions and report

pull/762/head
Jared Whiklo 6 years ago
parent
commit
1b91f82e69
  1. 30
      src/Flysystem/Fedora.php

30
src/Flysystem/Fedora.php

@ -10,6 +10,7 @@ use Drupal\flysystem\Plugin\FlysystemPluginInterface;
use Drupal\flysystem\Plugin\FlysystemUrlTrait; use Drupal\flysystem\Plugin\FlysystemUrlTrait;
use Drupal\islandora\Flysystem\Adapter\FedoraAdapter; use Drupal\islandora\Flysystem\Adapter\FedoraAdapter;
use Drupal\jwt\Authentication\Provider\JwtAuth; use Drupal\jwt\Authentication\Provider\JwtAuth;
use GuzzleHttp\Exception\ConnectException;
use GuzzleHttp\HandlerStack; use GuzzleHttp\HandlerStack;
use GuzzleHttp\Client; use GuzzleHttp\Client;
use Islandora\Chullo\IFedoraApi; use Islandora\Chullo\IFedoraApi;
@ -123,20 +124,27 @@ class Fedora implements FlysystemPluginInterface, ContainerFactoryPluginInterfac
*/ */
public function ensure($force = FALSE) { public function ensure($force = FALSE) {
// Check fedora root for sanity. // Check fedora root for sanity.
$response = $this->fedora->getResourceHeaders(''); try {
$response = $this->fedora->getResourceHeaders('');
if ($response->getStatusCode() != 200) { $statusCode = $response->getStatusCode();
return [[ $message = '%url returned %status';
'severity' => RfcLogLevel::ERROR, } catch (ConnectException $e) {
'message' => '%url returned %status', // Fedora is unavailable
'context' => [ $message = '%url is unavailable, cannot connect.';
'%url' => $this->fedora->getBaseUri(), $statusCode = 500;
'%status' => $response->getStatusCode(), }
if ($statusCode != 200) {
return [
[
'severity' => RfcLogLevel::ERROR,
'message' => $message,
'context' => [
'%url' => $this->fedora->getBaseUri(),
'%status' => $statusCode,
],
], ],
],
]; ];
} }
return []; return [];
} }

Loading…
Cancel
Save