10000 Add runtime exception for invalid JSON downloaded · symfony/symfony@c929d43 · GitHub
[go: up one dir, main page]

Skip to content

Commit c929d43

Browse files
committed
Add runtime exception for invalid JSON downloaded
1 parent fa279bd commit c929d43

File tree

3 files changed

+33
-6
lines changed

3 files changed

+33
-6
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Asset\Exception;
13+
14+
/**
15+
* Base RuntimeException for the Asset component.
16+
*
17+
* @author Fabien Potencier <fabien@symfony.com>
18+
*/
19+
class RuntimeException extends \RuntimeException implements ExceptionInterface
20+
{
21+
}

src/Symfony/Component/Asset/Tests/VersionStrategy/RemoteJsonManifestVersionStrategyTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,15 @@ public function testApplyVersionWhenKeyDoesNotExistInManifest()
4242
public function testMissingManifestFileThrowsException()
4343
{
4444
$this->expectException('RuntimeException');
45-
$this->expectExceptionMessage('Error loading asset manifest from URL "https://cdn.example.com/non-existent-file.json"');
45+
$this->expectExceptionMessage('HTTP 404 returned for "https://cdn.example.com/non-existent-file.json"');
4646
$strategy = $this->createStrategy('https://cdn.example.com/non-existent-file.json');
4747
$strategy->getVersion('main.js');
4848
}
4949

5050
public function testManifestFileWithBadJSONThrowsException()
5151
{
5252
$this->expectException('RuntimeException');
53-
$this->expectExceptionMessage('Error loading asset manifest from URL "https://cdn.example.com/manifest-invalid.json"');
53+
$this->expectExceptionMessage('Invalid JSON downloaded from "https://cdn.example.com/manifest-invalid.json"');
5454
$strategy = $this->createStrategy('https://cdn.example.com/manifest-invalid.json');
5555
$strategy->getVersion('main.js');
5656
}

src/Symfony/Component/Asset/VersionStrategy/RemoteJsonManifestVersionStrategy.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace Symfony\Component\Asset\VersionStrategy;
1313

14+
use Symfony\Component\Asset\Exception\RuntimeException;
15+
use Symfony\Contracts\HttpClient\Exception\DecodingExceptionInterface;
1416
use Symfony\Contracts\HttpClient\HttpClientInterface;
1517

1618
/**
@@ -57,10 +59,14 @@ public function applyVersion(string $path)
5759
private function getManifestPath(string $path): ?string
5860
{
5961
if (null === $this->manifestData) {
60-
$this->manifestData = $this->httpClient->request('GET', $this->manifestUrl, [
61-
'headers' => ['accept' => 'application/json'],
62-
'buffer' => true,
63-
])->toArray();
62+
try {
63+
$this->manifestData = $this->httpClient->request('GET', $this->manifestUrl, [
64+
'headers' => ['accept' => 'application/json'],
65+
'buffer' => true,
66+
])->toArray();
67+
} catch (DecodingExceptionInterface $e) {
68+
throw new RuntimeException(sprintf('Invalid JSON downloaded from "%s"', $this->manifestUrl), 0, $e);
69+
}
6470
}
6571

6672
return $this->manifestData[$path] ?? null;

0 commit comments

Comments
 (0)
0