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

Commit

Permalink
Catch exception.
Browse files Browse the repository at this point in the history
  • Loading branch information
Shawn Lin committed Aug 23, 2018
1 parent 39c5afc commit c8aeec0
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions code/YouTubeField.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit c8aeec0

Please sign in to comment.