diff --git a/core/modules/media/src/Plugin/Field/FieldFormatter/OEmbedFormatter.php b/core/modules/media/src/Plugin/Field/FieldFormatter/OEmbedFormatter.php index ab590ed41fed2b67cb34d81bebc23ab2472322de..19a79c1b8b49666cdfb16fe2bcecb4d109954151 100644 --- a/core/modules/media/src/Plugin/Field/FieldFormatter/OEmbedFormatter.php +++ b/core/modules/media/src/Plugin/Field/FieldFormatter/OEmbedFormatter.php @@ -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; } diff --git a/core/modules/media/tests/src/FunctionalJavascript/MediaSourceOEmbedVideoTest.php b/core/modules/media/tests/src/FunctionalJavascript/MediaSourceOEmbedVideoTest.php index 5ce73e2336f2af3aeb89dc51ebe87295663eeb8a..38e502d3e9ab3a12acababaa205205b3719e6207 100644 --- a/core/modules/media/tests/src/FunctionalJavascript/MediaSourceOEmbedVideoTest.php +++ b/core/modules/media/tests/src/FunctionalJavascript/MediaSourceOEmbedVideoTest.php @@ -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();