From c8aeec05a9b8fd815ed7250a7d793fa3a9d239f3 Mon Sep 17 00:00:00 2001 From: Shawn Lin Date: Thu, 23 Aug 2018 22:51:15 +0000 Subject: [PATCH] Catch exception. --- code/YouTubeField.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/code/YouTubeField.php b/code/YouTubeField.php index a3eb774..ab92ab2 100644 --- a/code/YouTubeField.php +++ b/code/YouTubeField.php @@ -20,8 +20,10 @@ public function Field($properties = array()) Requirements::javascript('https://apis.google.com/js/client.js?onload=googleApiClientReady'); } elseif (!empty($this->value) && self::url_parser($this->value)) { $client = new GuzzleHttp\Client(); - $res = $client->get('https://www.youtube.com/oembed?url=https://www.youtube.com/watch?v=' . $this->value . '&format=json'); - if ($res->getStatusCode() == '200' && $data = json_decode($res->getBody())) { + try { + $res = $client->get('https://www.youtube.com/oembed?url=https://www.youtube.com/watch?v=' . $this->value . '&format=json'); + } catch (Exception $e) {} + if (isset($res) && $res->getStatusCode() == '200' && $data = json_decode($res->getBody())) { $api_data = new stdClass(); $api_data->id = $this->value; $api_data->snippet = new stdClass();