Skip to content

Commit

Permalink
Catch Flysystem exceptions and report (#762)
Browse files Browse the repository at this point in the history
  • Loading branch information
whikloj authored Mar 2, 2020
1 parent 26bfd76 commit 2a1024c
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions src/Flysystem/Fedora.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
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;
Expand Down Expand Up @@ -123,20 +124,28 @@ public function getAdapter() {
*/
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 [];
}

Expand Down

0 comments on commit 2a1024c

Please sign in to comment.