Skip to content
This repository was archived by the owner on Sep 9, 2022. It is now read-only.

Commit 771a474

Browse files
authored
Merge pull request #25 from timezoneone/tzo/fixes
Catch uncaught error triggered when youtube id not found.
2 parents 39c5afc + c8aeec0 commit 771a474

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

code/YouTubeField.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ public function Field($properties = array())
2020
Requirements::javascript('https://apis.google.com/js/client.js?onload=googleApiClientReady');
2121
} elseif (!empty($this->value) && self::url_parser($this->value)) {
2222
$client = new GuzzleHttp\Client();
23-
$res = $client->get('https://www.youtube.com/oembed?url=https://www.youtube.com/watch?v=' . $this->value . '&format=json');
24-
if ($res->getStatusCode() == '200' && $data = json_decode($res->getBody())) {
23+
try {
24+
$res = $client->get('https://www.youtube.com/oembed?url=https://www.youtube.com/watch?v=' . $this->value . '&format=json');
25+
} catch (Exception $e) {}
26+
if (isset($res) && $res->getStatusCode() == '200' && $data = json_decode($res->getBody())) {
2527
$api_data = new stdClass();
2628
$api_data->id = $this->value;
2729
$api_data->snippet = new stdClass();

0 commit comments

Comments
 (0)