Unverified Commit ee0a221d authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3188920 by xjm: Make Guzzle exception handling forward-compatible with Guzzle 7

parent 4aba8c47
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -38,7 +38,7 @@
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Route;
use Drupal\user\Entity\User;
use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\Exception\TransferException;

/**
 * Do not run the task during the current installation request.
@@ -1442,7 +1442,7 @@ function install_retrieve_file($uri, $destination) {
      return FALSE;
    }
  }
  catch (RequestException $e) {
  catch (TransferException $e) {
    return FALSE;
  }
  return file_put_contents($path, $data) !== FALSE;
@@ -1462,7 +1462,7 @@ function install_check_localization_server($uri) {
    \Drupal::httpClient()->head($uri);
    return TRUE;
  }
  catch (RequestException $e) {
  catch (TransferException $e) {
    return FALSE;
  }
}
+2 −2
Original line number Diff line number Diff line
@@ -8,7 +8,7 @@
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Symfony\Component\DependencyInjection\ContainerInterface;
use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\Exception\TransferException;
use GuzzleHttp\ClientInterface;

/**
@@ -122,7 +122,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
        $response = $this->httpClient->get($form_state->getValue('remote'));
        $data = (string) $response->getBody();
      }
      catch (RequestException $e) {
      catch (TransferException $e) {
        $this->logger('aggregator')->warning('Failed to download OPML file due to "%error".', ['%error' => $e->getMessage()]);
        $this->messenger()->addStatus($this->t('Failed to download OPML file due to "%error".', ['%error' => $e->getMessage()]));
        return;
+2 −2
Original line number Diff line number Diff line
@@ -8,7 +8,7 @@
use Drupal\Core\Http\ClientFactory;
use Drupal\Core\Messenger\MessengerInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\Exception\TransferException;
use GuzzleHttp\Psr7\Request;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
@@ -125,7 +125,7 @@ public function fetch(FeedInterface $feed) {
      }
      return TRUE;
    }
    catch (RequestException $e) {
    catch (TransferException $e) {
      $this->logger->warning('The feed from %site seems to be broken because of error "%error".', ['%site' => $feed->label(), '%error' => $e->getMessage()]);
      $this->messenger->addWarning(t('The feed from %site seems to be broken because of error "%error".', ['%site' => $feed->label(), '%error' => $e->getMessage()]));
      return FALSE;
+6 −0
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@

use Drupal\Core\File\FileSystemInterface;
use Drupal\Core\Url;
use GuzzleHttp\Exception\ConnectException;
use GuzzleHttp\Exception\RequestException;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
@@ -272,6 +273,11 @@ function locale_translation_http_check($uri) {
      $logger->notice('HTTP request to @url failed with error: @error.', ['@url' => $uri, '@error' => $response->getStatusCode() . ' ' . $response->getReasonPhrase()]);
    }
  }
  // We need to handle ConnectException separately because in Guzzle 7 it
  // doesn't have a getResponse() method, so the above will fatal.
  catch (ConnectException $e) {
    $logger->notice('HTTP request to @url failed with error: @error.', ['@url' => $uri, '@error' => $e->getMessage()]);
  }

  return FALSE;
}
+2 −2
Original line number Diff line number Diff line
@@ -8,7 +8,7 @@
use Drupal\Core\Cache\UseCacheBackendTrait;
use Drupal\Core\Config\ConfigFactoryInterface;
use GuzzleHttp\ClientInterface;
use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\Exception\TransferException;

/**
 * Retrieves and caches information about oEmbed providers.
@@ -81,7 +81,7 @@ public function getAll() {
    try {
      $response = $this->httpClient->request('GET', $this->providersUrl);
    }
    catch (RequestException $e) {
    catch (TransferException $e) {
      throw new ProviderException("Could not retrieve the oEmbed provider database from $this->providersUrl", NULL, $e);
    }

Loading