Skip to content
Snippets Groups Projects
Commit 1eb77a55 authored by Stefan Galinski's avatar Stefan Galinski :video_game:
Browse files

[BUGFIX] Fix the broken error handling

parent 0a8ffe39
No related branches found
No related tags found
No related merge requests found
......@@ -20,6 +20,7 @@ namespace SGalinski\SgVimeo\Controller;
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use http\Exception\RuntimeException;
use SGalinski\SgVimeo\Service\VimeoService;
use TYPO3\CMS\Core\Imaging\ImageManipulation\CropVariantCollection;
use TYPO3\CMS\Core\Resource\FileReference;
......@@ -64,21 +65,21 @@ class VimeoController extends ActionController {
$clientSecret,
$personalAccessToken
);
$response = $vimeoService->getVimeoData($id, $maxResultsWithFilters);
$response = $this->mapVimeoApiResponseWithPossibleCustomThumbnails($response);
if ($response === NULL) {
try {
$response = $vimeoService->getVimeoData($id, $maxResultsWithFilters);
$response = $this->mapVimeoApiResponseWithPossibleCustomThumbnails($response);
if ($response === NULL) {
return;
}
} catch (\Exception $exception) {
$this->view->assign('error', $exception->getMessage());
return;
}
if (is_array($response['items'])) {
$response['items'] = array_filter($response['items'], function ($item) use ($filterIds) {
$videoId = (string) $item['videoId'];
foreach ($filterIds as $filterId) {
if ($videoId === $filterId) {
return FALSE;
}
}
return TRUE;
return !in_array($videoId, $filterIds, TRUE);
});
// Fix the array indexes from previous filtering
......@@ -89,7 +90,6 @@ class VimeoController extends ActionController {
}
foreach ($response['items'] as &$item) {
/*
* Check if link is of the form "https://vimeo.com/123456789", not "https://vimeo.com/username/videoname".
* Just checks if the end of `link` is the same as `videoId`, and if not, it replaces `link`.
......@@ -131,6 +131,15 @@ class VimeoController extends ActionController {
return NULL;
}
if (isset($response['items'][0]['error'])) {
$message = $response['items'][0]['error'];
if (isset($response['items'][0]['developer_message'])) {
$message .= ' (' . $response['items'][0]['developer_message'] . ')';
}
throw new \RuntimeException($message);
}
$contentElementUid = (int) $this->configurationManager->getContentObject()->data['uid'];
if ($contentElementUid <= 0) {
return $response;
......
......@@ -124,7 +124,7 @@ class VimeoService implements LoggerAwareInterface {
$response['items'] = $this->addVideoIdsToResponse($this->getChannelVideos($channelId));
$response['kind'] = 'channel';
} else {
$response['items'] = $this->addVideoIdsToResponse($this->getVideo((int) $vimeoId));
$response['items'] = $this->addVideoIdsToResponse($this->getVideo($vimeoId));
$response['kind'] = 'video';
}
......@@ -188,11 +188,10 @@ class VimeoService implements LoggerAwareInterface {
// log error & return here, since the response was not OK
if ($response['status'] !== 200) {
$this->logger->error('sg_vimeo API Request failed, got the following response:', $response);
return NULL;
return [$response['body']];
}
// @TODO: we could check $response['headers‘]['X-RateLimit-Remaining'] here for remaining quota
if (array_key_exists('paging', $response['body'])) {
$amountOfVideosInResponse = is_countable($response['body']['data']) ? count($response['body']['data']) : 0;
$this->amountOfVideosFetched += $amountOfVideosInResponse;
......@@ -228,16 +227,17 @@ class VimeoService implements LoggerAwareInterface {
* Returns a single video for the given $videoId
*
* @see https://developer.vimeo.com/api/reference/videos#get_video
* @param int $videoId
* @param string $videoId
* @return array|null
*/
public function getVideo(int $videoId): ?array {
public function getVideo(string $videoId): ?array {
// use field filtering, to save on quota, see: https://developer.vimeo.com/guidelines/rate-limiting
$fieldsToSelect = 'uri,name,description,link,embed,pictures,release_time,width,height';
try {
$response = $this->vimeoApiClient->request(self::API_VIDEO . $videoId . '?fields=' . $fieldsToSelect);
} catch (VimeoRequestException $e) {
$response = NULL;
throw $e;
}
return $this->preprocessApiResponse($response);
......@@ -259,6 +259,7 @@ class VimeoService implements LoggerAwareInterface {
);
} catch (VimeoRequestException $e) {
$response = NULL;
throw $e;
}
return $this->preprocessApiResponse($response);
......@@ -280,6 +281,7 @@ class VimeoService implements LoggerAwareInterface {
);
} catch (VimeoRequestException $e) {
$response = NULL;
throw $e;
}
return $this->preprocessApiResponse($response);
......
......@@ -41,7 +41,7 @@ plugin.tx_sgvimeo {
If you have a video which is not available to the public, but you want to show it on your website, you need an
authenticated personal access token. You can find a guide, on how to generate such a token here:
https://vimeo.zendesk.com/hc/en-us/articles/360042445032-How-do-I-generate-a-personal-access-token- .
https://vimeo.zendesk.com/hc/en-us/articles/360042445032-How-do-I-generate-a-personal-access-token-
The following requirements have to be met, for the private video to show up:
* the video has to be hosted on the same vimeo account, that was used to configure the clientSecret & clientId (vimeo app)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment