|
8 | 8 | use App\Enum\NamingConvention; |
9 | 9 | use App\Enum\Setting; |
10 | 10 | use App\Exception\ExitException; |
| 11 | +use App\Exception\ForceRetryException; |
11 | 12 | use App\Exception\InvalidValueException; |
12 | 13 | use App\Exception\TooManyRetriesException; |
13 | 14 | use App\Exception\UnreadableFileException; |
|
33 | 34 | use Symfony\Component\Console\Input\InputOption; |
34 | 35 | use Symfony\Component\Console\Output\OutputInterface; |
35 | 36 | use Symfony\Component\Console\Style\SymfonyStyle; |
| 37 | +use Symfony\Component\HttpClient\Exception\ClientException; |
| 38 | +use Symfony\Component\HttpFoundation\Response; |
36 | 39 |
|
37 | 40 | #[AsCommand('download')] |
38 | 41 | final class DownloadCommand extends Command |
@@ -303,10 +306,19 @@ protected function execute(InputInterface $input, OutputInterface $output): int |
303 | 306 | } catch (UnreadableFileException) { |
304 | 307 | $hash = hash_init('md5'); |
305 | 308 | } |
306 | | - foreach ($responses as $response) { |
307 | | - $chunk = $response->getContent(); |
308 | | - $writer->writeChunk($targetFile, $chunk, $chunkSize); |
309 | | - hash_update($hash, $chunk); |
| 309 | + try { |
| 310 | + foreach ($responses as $response) { |
| 311 | + $chunk = $response->getContent(); |
| 312 | + $writer->writeChunk($targetFile, $chunk, $chunkSize); |
| 313 | + hash_update($hash, $chunk); |
| 314 | + } |
| 315 | + } catch (ClientException $e) { |
| 316 | + if ($e->getCode() === Response::HTTP_REQUESTED_RANGE_NOT_SATISFIABLE) { |
| 317 | + $writer->remove($targetFile); |
| 318 | + throw new ForceRetryException(); |
| 319 | + } |
| 320 | + |
| 321 | + throw $e; |
310 | 322 | } |
311 | 323 | $hash = hash_final($hash); |
312 | 324 | $writer->finalizeWriting($targetFile, $hash); |
|
0 commit comments