Verified Commit 8f38fc7e authored by Dave Long's avatar Dave Long
Browse files

Issue #3402540 by mfb, dadderley, smustgrave, longwave: 'Could not retrieve...

Issue #3402540 by mfb, dadderley, smustgrave, longwave: 'Could not retrieve the remote URL' error message is vague
parent baf0e409
Loading
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -177,7 +177,11 @@ public function viewElements(FieldItemListInterface $items, $langcode) {
        $resource = $this->resourceFetcher->fetchResource($resource_url);
      }
      catch (ResourceException $exception) {
        $this->logger->error("Could not retrieve the remote URL (@url).", ['@url' => $value]);
        $this->logger->error("Could not retrieve the remote URL (@url): %error", [
          '@url' => $value,
          '%error' => $exception->getPrevious() ? $exception->getPrevious()->getMessage() : $exception->getMessage(),
          'exception' => $exception,
        ]);
        continue;
      }

+21 −1
Original line number Diff line number Diff line
@@ -5,6 +5,8 @@
namespace Drupal\Tests\media\FunctionalJavascript;

use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Database\Database;
use Drupal\dblog\Controller\DbLogController;
use Drupal\media\Entity\Media;
use Drupal\media\Entity\MediaType;
use Drupal\media_test_oembed\Controller\ResourceController;
@@ -22,7 +24,7 @@ class MediaSourceOEmbedVideoTest extends MediaSourceTestBase {
  /**
   * {@inheritdoc}
   */
  protected static $modules = ['media_test_oembed'];
  protected static $modules = ['media_test_oembed', 'dblog'];

  /**
   * {@inheritdoc}
@@ -190,6 +192,24 @@ public function testMediaOEmbedVideoSource() {
    // should have deduced the correct one.
    $this->assertStringEndsWith('.png', $thumbnail);

    // Test ResourceException logging.
    $video_url = 'https://vimeo.com/1111';
    ResourceController::setResourceUrl($video_url, $this->getFixturesDirectory() . '/video_vimeo.json');
    $this->drupalGet("media/add/$media_type_id");
    $assert_session->fieldExists('Remote video URL')->setValue($video_url);
    $assert_session->buttonExists('Save')->press();
    $assert_session->addressEquals('admin/content/media');
    ResourceController::setResource404($video_url);
    $this->drupalGet($this->assertLinkToCreatedMedia());
    $row = Database::getConnection()->select('watchdog')
      ->fields('watchdog', ['message', 'variables'])
      ->orderBy('wid', 'DESC')
      ->range(0, 1)
      ->execute()
      ->fetchObject();
    $message = (string) DbLogController::create($this->container)->formatMessage($row);
    $this->assertStringContainsString('resulted in a `404 Not Found` response', $message);

    // Test anonymous access to media via iframe.
    $this->drupalLogout();