Commit c22ff8c2 authored by Klinton Ngkoutsai's avatar Klinton Ngkoutsai Committed by Nicolas Borda
Browse files

Issue #3108232 by ngkoutsaik, strozx, ipwa: Uncaught exception if server can't resolve host

parent 33252a0b
Loading
Loading
Loading
Loading
+13 −5
Original line number Diff line number Diff line
@@ -100,12 +100,20 @@ class InstagramWithoutApi extends BlockBase {

      $url = "https://www.instagram.com/{$this->configuration['name']}";

      try {
        // Get Response file_get_contents($url);
        $instagram_url = \Drupal::httpClient()->get($url);
        $response = (string) $instagram_url->getBody();
      }
      catch (\Exception $e) {
        \Drupal::logger('instagram_without_api')->error($e->getMessage());
      }

      if (empty($response)) {
        //Can't find Url
        return [];
        // Can't find Url. Return a message letting user know what is the problem.
        return [
          '#markup' => 'Could not reach Instagram server',
        ];
      }

      // the start position