Problem/Motivation
when YouTube videos are embedded via the media module there is no proper error handling for 403 oEmbed response.
Sometimes, the oEmbed response from YouTube is “Forbidden”. Either because a video is not fully uploaded yet, or because of an ongoing YouTube content check or incomplete thumbnail generate etc…
so if YouTube states that the video is not ready, it returns “forbidden” and this leads to two issues in drupal:
- blank page “the website encountered an erro and the log file states: Client error: `GET https://www.youtube.com/oembed?url=https://youtu.be/YOURVIDEO` resulted in a `403 Forbidden` response: Forbidden
- and in addition to that it causes a watchdog sql error because somehow the message is no utf8 encoded
(“General error: 1366 Incorrect string value: '…' for column 'message'(…)Array ( [:db_insert_placeholder_0] => 1 [:db_insert_placeholder_1] => media [:db_insert_placeholder_2] => Client error: `GET https://i.ytimg.com/vi/YOURTHUMBNAIL/hqdefault.jpg` resulted in a `404 Not Found` response: ���JFIF��� !"" (truncated...)) .
Steps to reproduce
- create a media field for oEmbed media and assign YouTube
- upload a video on YouTube but do not save the upload screen on YouTube (just keep it open at the very first page of the upload form)
- copy the YouTube video link that is already generated
- enter that link in drupals YouTube field and save
- this triggers an error (no valid oEmbed resource)
- save again
- this triggers the crash
Proposed resolution
Provide error handling in case the response from YouTube is “forbidden” and return a friendly message to the user.