fix: 🐛 fix crash if no cache is configured
Some checks failed
repod / xml (push) Successful in 1m10s
repod / php (push) Failing after 44s
repod / nodejs (push) Successful in 1m25s
repod / release (push) Has been skipped

This commit is contained in:
Michel Roux 2024-06-14 19:32:26 +02:00
parent bc8db22fce
commit 42bfdb530b

View File

@ -10,12 +10,14 @@ use OCA\RePod\AppInfo\Application;
use OCP\AppFramework\Controller; use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\JSONResponse; use OCP\AppFramework\Http\JSONResponse;
use OCP\Http\Client\IClientService; use OCP\Http\Client\IClientService;
use OCP\ICacheFactory;
use OCP\IRequest; use OCP\IRequest;
class PodcastController extends Controller class PodcastController extends Controller
{ {
public function __construct( public function __construct(
IRequest $request, IRequest $request,
private ICacheFactory $cacheFactory,
private IClientService $clientService, private IClientService $clientService,
private PodcastDataReader $podcastDataReader private PodcastDataReader $podcastDataReader
) { ) {
@ -27,10 +29,12 @@ class PodcastController extends Controller
* @NoCSRFRequired * @NoCSRFRequired
*/ */
public function index(string $url): JSONResponse { public function index(string $url): JSONResponse {
try { if ($this->cacheFactory->isLocalCacheAvailable()) {
$podcast = $this->podcastDataReader->tryGetCachedPodcastData($url); try {
} catch (\Exception $e) { $podcast = $this->podcastDataReader->tryGetCachedPodcastData($url);
$podcast = null; } catch (\Exception $e) {
$podcast = null;
}
} }
if ($podcast) { if ($podcast) {
@ -41,9 +45,11 @@ class PodcastController extends Controller
$feed = $client->get($url); $feed = $client->get($url);
$podcast = PodcastData::parseRssXml((string) $feed->getBody()); $podcast = PodcastData::parseRssXml((string) $feed->getBody());
try { if ($this->cacheFactory->isLocalCacheAvailable()) {
$this->podcastDataReader->trySetCachedPodcastData($url, $podcast); try {
} catch (\Exception $e) { $this->podcastDataReader->trySetCachedPodcastData($url, $podcast);
} catch (\Exception $e) {
}
} }
return new JSONResponse($podcast, $feed->getStatusCode()); return new JSONResponse($podcast, $feed->getStatusCode());