Skip to content
This repository was archived by the owner on Nov 14, 2019. It is now read-only.

Commit e211f2d

Browse files
committed
feature #59 improve error messages when the download fails (xabbuh)
This PR was merged into the 1.0-dev branch. Discussion ---------- improve error messages when the download fails This pull request addresses #48. Commits ------- cadccd3 improve error messages when the download fails
2 parents e0b7ebf + cadccd3 commit e211f2d

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/Symfony/Installer/NewCommand.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Distill\Distill;
66
use Distill\Strategy\MinimumSize;
77
use GuzzleHttp\Client;
8+
use GuzzleHttp\Exception\ClientException;
89
use GuzzleHttp\Message\Response;
910
use GuzzleHttp\Subscriber\Progress\Progress;
1011
use Symfony\Component\Console\Command\Command;
@@ -232,7 +233,27 @@ private function download()
232233
// store the file in a temporary hidden directory with a random name
233234
$this->compressedFilePath = getcwd().DIRECTORY_SEPARATOR.'.'.uniqid(time()).DIRECTORY_SEPARATOR.'symfony.'.pathinfo($symfonyArchiveFile, PATHINFO_EXTENSION);
234235

235-
$response = $client->get($symfonyArchiveFile);
236+
try {
237+
$response = $client->get($symfonyArchiveFile);
238+
} catch (ClientException $e) {
239+
if ($e->getCode() === 403 || $e->getCode() === 404) {
240+
throw new \RuntimeException(sprintf(
241+
"The selected version (%s) cannot be installed because it does not exist.\n".
242+
"Try the special \"latest\" version to install the latest stable Symfony release:\n".
243+
'php symfony %s %s latest',
244+
$this->version,
245+
$this->getName(),
246+
$this->projectName
247+
));
248+
} else {
249+
throw new \RuntimeException(sprintf(
250+
"The selected version (%s) couldn\'t be downloaded because of the following error:\n%s",
251+
$this->version,
252+
$e->getMessage()
253+
));
254+
}
255+
}
256+
236257
$this->fs->dumpFile($this->compressedFilePath, $response->getBody());
237258

238259
if (null !== $progressBar) {

0 commit comments

Comments
 (0)