Skip to content

Commit 7ec2873

Browse files
authored
Merge pull request #167 from os2display/feature/display-1019-feed-errors-cleanup
DISPLAY-1019: Removed references to non-existing exception
2 parents 144cc54 + bb76bfe commit 7ec2873

File tree

3 files changed

+8
-21
lines changed

3 files changed

+8
-21
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ All notable changes to this project will be documented in this file.
44

55
## [Unreleased]
66

7+
- [#167](https://github.com/os2display/display-api-service/pull/167)
8+
- Removed references to non-existing exception.
79
- [#166](https://github.com/os2display/display-api-service/pull/166)
810
- Wrapped feeds in try-catch to avoid throwing errors.
911
- Added unpublished flow to EventDatabase feed when occurrence returns 404.

src/DataProvider/FeedDataProvider.php

+4-8
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use ApiPlatform\Core\DataProvider\RestrictedDataProviderInterface;
88
use App\Entity\Tenant\Feed;
99
use App\Entity\User;
10-
use App\Exceptions\MissingFeedConfigurationException;
1110
use App\Repository\FeedRepository;
1211
use App\Repository\PlaylistSlideRepository;
1312
use App\Service\FeedService;
@@ -19,7 +18,6 @@
1918
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
2019
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
2120
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
22-
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
2321

2422
final class FeedDataProvider implements ItemDataProviderInterface, RestrictedDataProviderInterface
2523
{
@@ -58,7 +56,7 @@ public function getItem(string $resourceClass, $id, string $operationName = null
5856
// Get result. If there is a result this is returned.
5957
try {
6058
$feed = $queryBuilder->getQuery()->getOneOrNullResult();
61-
} catch (NonUniqueResultException $exception) {
59+
} catch (NonUniqueResultException) {
6260
return null;
6361
}
6462

@@ -91,12 +89,10 @@ public function getItem(string $resourceClass, $id, string $operationName = null
9189
if ('get' === $operationName || 'get_feed_data' === $operationName) {
9290
return new JsonResponse($this->feedService->getData($feed), 200);
9391
}
94-
} catch (MissingFeedConfigurationException $e) {
95-
$this->logger->error(sprintf('Missing configuration for feed with id "%s" with message "%s"', $feed->getId()->jsonSerialize(), $e->getMessage()));
96-
} catch (\JsonException $e) {
97-
$this->logger->error(sprintf('JSON decode for feed with id "%s" with error "%s"', $feed->getId()->jsonSerialize(), $e->getMessage()));
98-
} catch (ClientExceptionInterface|RedirectionExceptionInterface|ServerExceptionInterface|TransportExceptionInterface $e) {
92+
} catch (ClientExceptionInterface|RedirectionExceptionInterface|ServerExceptionInterface $e) {
9993
$this->logger->error(sprintf('Communication error "%s"', $e->getMessage()));
94+
} catch (\Throwable $e) {
95+
$this->logger->error(sprintf('Feed data error. ID: %s, MESSAGE: %s', $feed->getId()->jsonSerialize(), $e->getMessage()));
10096
}
10197
}
10298

src/Service/FeedService.php

+2-13
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,12 @@
66
use ApiPlatform\Core\Bridge\Symfony\Routing\RouteNameGenerator;
77
use App\Entity\Tenant\Feed;
88
use App\Entity\Tenant\FeedSource;
9-
use App\Exceptions\MissingFeedConfigurationException;
109
use App\Exceptions\UnknownFeedTypeException;
1110
use App\Feed\FeedTypeInterface;
1211
use Psr\Cache\CacheItemInterface;
1312
use Symfony\Component\HttpFoundation\Request;
1413
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
1514
use Symfony\Contracts\Cache\CacheInterface;
16-
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
17-
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
18-
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
19-
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
2015

2116
class FeedService
2217
{
@@ -99,20 +94,14 @@ public function getFeedSourceConfigUrl(FeedSource $feedSource, string $name): st
9994
*
10095
* @return array|null
10196
* Array with feed data
102-
*
103-
* @throws MissingFeedConfigurationException
104-
* @throws \JsonException
105-
* @throws ClientExceptionInterface
106-
* @throws RedirectionExceptionInterface
107-
* @throws ServerExceptionInterface
108-
* @throws TransportExceptionInterface
10997
*/
11098
public function getData(Feed $feed): ?array
11199
{
112100
// Get feed id.
113101
$feedId = $feed->getId()?->jsonSerialize();
102+
114103
if (is_null($feedId)) {
115-
throw new MissingFeedConfigurationException('Missing feed ID');
104+
return null;
116105
}
117106

118107
/** @var CacheItemInterface $cacheItem */

0 commit comments

Comments
 (0)