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

improve error messages when the download fails #59

Merged
merged 1 commit into from
Dec 2, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion src/Symfony/Installer/NewCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Distill\Distill;
use Distill\Strategy\MinimumSize;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\ClientException;
use GuzzleHttp\Message\Response;
use GuzzleHttp\Subscriber\Progress\Progress;
use Symfony\Component\Console\Command\Command;
Expand Down Expand Up @@ -232,7 +233,27 @@ private function download()
// store the file in a temporary hidden directory with a random name
$this->compressedFilePath = getcwd().DIRECTORY_SEPARATOR.'.'.uniqid(time()).DIRECTORY_SEPARATOR.'symfony.'.pathinfo($symfonyArchiveFile, PATHINFO_EXTENSION);

$response = $client->get($symfonyArchiveFile);
try {
$response = $client->get($symfonyArchiveFile);
} catch (ClientException $e) {
if ($e->getCode() === 403 || $e->getCode() === 404) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The check for 403 can be removed once the download site returns proper error codes when a file could not be found.

throw new \RuntimeException(sprintf(
"The selected version (%s) cannot be installed because it does not exist.\n".
"Try the special \"latest\" version to install the latest stable Symfony release:\n".
'php symfony %s %s latest',
$this->version,
$this->getName(),
$this->projectName
));
} else {
throw new \RuntimeException(sprintf(
"The selected version (%s) couldn\'t be downloaded because of the following error:\n%s",
$this->version,
$e->getMessage()
));
}
}

$this->fs->dumpFile($this->compressedFilePath, $response->getBody());

if (null !== $progressBar) {
Expand Down