/** * Handle response errors * @param $status - The response status object * @param $content - Json content from the provider * @param $apiUrl - The URL for the providers API * @throws VideoNotFoundException - Video cannot be found */ protected function checkForResponseErrors($status, $content, $apiUrl) { $error_code = ""; // true parameter here has json_decode return an array, rather than an object $error_json = json_decode($content, true); if (isset($error_json['error']['code'])) { $error_code = $error_json['error']['code']; } if ($error_code == self::VIDEO_NOT_FOUND_ERROR) { throw new VideoNotFoundException($status, $content, $apiUrl); } parent::checkForResponseErrors($status, $content, $apiUrl); }
protected function checkForResponseErrors($status, $content, $apiUrl) { wfProfileIn(__METHOD__); if ($content == $this->videoId . ' not found.') { wfProfileOut(__METHOD__); throw new VideoNotFoundException($status, $content, $apiUrl); } wfProfileOut(__METHOD__); // return default parent::checkForResponseErrors($status, $content, $apiUrl); }
/** * Handle response errors * @param $status - The response status object * @param $content - content from the provider * @param $apiUrl - The URL for the providers API * @throws NegativeResponseException * @throws VideoIsPrivateException - Video is private and cannot be viewed * @throws VideoNotFoundException - Video cannot be found * @throws VideoWrongApiCall - Youtube returns 400 response error code */ protected function checkForResponseErrors($status, $content, $apiUrl) { wfProfileIn(__METHOD__); $code = $content['error']['code']; if ($code == 400) { wfProfileOut(__METHOD__); WikiaLogger::instance()->error('Youtube API call returns 400', ['content' => $content]); throw new VideoWrongApiCall($status, $content, $apiUrl); } wfProfileOut(__METHOD__); // return default parent::checkForResponseErrors($status, $content, $apiUrl); }
protected function checkForResponseErrors($status, $content, $apiUrl) { wfProfileIn(__METHOD__); // check if still exists $code = $status->errors[0]['params'][0]; if ($code == 404) { wfProfileOut(__METHOD__); throw new VideoNotFoundException($status, $content, $apiUrl); } // interpret error XML response $sp = new SimplePie(); $sp->set_raw_data($content); $sp->init(); // check if private $googleShemas = 'http://schemas.google.com/g/2005'; if (isset($sp->data['child'][$googleShemas])) { $err = $sp->data['child'][$googleShemas]['errors'][0]['child'][$googleShemas]['error'][0]['child'][$googleShemas]['internalReason'][0]['data']; if ($err == 'Private video') { wfProfileOut(__METHOD__); throw new VideoIsPrivateException($status, $content, $apiUrl); } } // check if quota exceeded if (isset($sp->data['child'][''])) { $err = $sp->data['child']['']['errors'][0]['child']['']['error'][0]['child']['']['code'][0]['data']; if ($err == 'too_many_recent_calls') { wfProfileOut(__METHOD__); throw new VideoQuotaExceededException($status, $content, $apiUrl); } } wfProfileOut(__METHOD__); // return default parent::checkForResponseErrors($status, $content, $apiUrl); }